.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Change image in gridview after binding

Posted By:      Posted Date: September 27, 2010    Points: 0   Category :ASP.Net

I have a need to change the image (bound) in a gridview after it has been databound.  Basically i need to assign a photo to a record and I want to change the image url for that row.  I can change the text in any of the cells of the row but I can't seem to find property for the imageurl.

This is what I do to change the text(cell 5).

int index = int.Parse(Session["NSI"].ToString());

GridViewRow row1 = GridView1.Rows[index];
row1.Cells[5].Text = "just some text";

But now I need to change the image url for cell 0

something along the lines of ...

row1.Cells[0].ImageUrl = "~images\photos\12345.jpg";

How do I get to that property?

Thank you.

View Complete Post

More Related Resource Links

Binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Here is the code for binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Binding GridView with SqlDataSource at runtime?


Hi, I want to create a generic page which contains a gridview and sqldatasource. I want to put these two controls on .aspx (C#) page but bind them at runtime. It should have selectcommand, updatecommand, deletecommand and insertcommand. Stored procedures are created for that. Help is needed to make it. Please post some link or code. Regards, ap.

Gridview with Image Button


i have a gridview and i want to perform edit and delete with an image button

but unable to figure out the events and how i m gonna make my grid into edit mode ??

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                <asp:TemplateField HeaderText="S.No">
                        <asp:Label ID="Label1" runat="server" Text='<%# Container.DataItemIndex+1 %>'></asp:Label>
                <asp:TemplateField HeaderText="Edit">
                        <asp:ImageButton ID="ImageButton1" runat="server" ImageAlign="Middle" 
                            ImageUrl="~/image/ico_edit.gif" CommandName="Edit" 
                            onclick="ImageButton1_Click" />
                <asp:TemplateField HeaderText="Delete">

change image button image


i am making a web form with a VB code behind.  on the form I have a down arrow imageButton that when pressed hides certain data.  what i want to do is change the button to an up arrow and vice versa whenever pressed.  i have both images loaded onto my project already.  any suggestions.

thank you

Change data on gridview bind


Hi there,

Simple little problem. i have a gridview that shows products assigned to a customers job. They are displayed in exVAT prices. To make it easier i want to show the inc VAT prices. How can i add VAT to 1 column in this table?

How To display image in GridView as hyperlink


Hello Everyone 

Could someone please help me with a little issue....

I was able to save the image in the database as binary....... but now i don´t know how to display it in the GridView as a hyperlink.

I´ve read something about ImageField..... I´d appreciate any help .


Need some help BINDING to Gridview


Here is how I set this up....Still not working.

  •     Dim cs As ConnectionStringSettings   
  •     cs = ConfigurationManager.ConnectionStrings("ConnectionStringVendors")   
  •     Dim connString As String = cs.ConnectionString   
  •     Dim dbConnection As New SqlConnection(connString)   
  •     Dim query As String  
  •     Dim query1 As String  
  •     query = "SELECT keyID, projectNum, projectDescripti
  • Binding xml data (which is return from Url) to gridview


    I have used Yahoo BOSS API for internal search. This API return string and i want to bind it with gridview. How can i achieve this following is the code

    string AppId = "sRP_q9bV34HI_zNyuahPFBGnf1SHyBaIKCtvEjB89EuiNJI6fcfSwAFbwAFSsCV_";
    //string Query = "site:way2k.com engineering colleges in pune";
    string Query = "colleges in pune"; int NumResults = 10;
         int NumResults = 10;
    System.Net.WebClient webClient = new System.Net.WebClient(); request = string.Format( "http://boss.yahooapis.com/ysearch/web/v1/{1}?appid={0}&format=xml&results={2}", AppId, Query, NumResults); byte[] response = webClient.DownloadData(request); string responseXML = System.Text.UTF8Encoding.UTF8.GetString(response); return responseXML;

    this code returns result in xml format, how can i bind this XML to gridview so that it looks like search result

    Can't change Gridview row colors or styles in the DataBound event


    I was highlighting certain rows in my gridview using code like this in the DataBound event:

            if (e.Row.RowType == DataControlRowType.DataRow)
                int vendorCheck = 0;
                //TODO make this shorter
                if (DataBinder.Eval(e.Row.DataItem, "vendorId") != System.DBNull.Value)

    change css and image url

    HiI have a masterpage on a site, in order to use the site the user has to login first. And after that I  would like to customize the masterpage with a unique css file and a unique imageurl for a image on the masterpage. Whar is the preferable way to achive this?

    Editing Image in Gridview VB.net

    Hi, i'm back again and would like to seek help and advises from you experts on how to deal with problem. I have a table that accepts news data like title, content, link and a single image to be uploaded and attached to the database (not on file server). Now i want this Image Column (varbinary datatype) to be edited in case. When I tried puting an html fileupload in editing mode using gridview, I am getting error from the Image Column conversion like Image type cannot be converted into string. I know there is this scenario of reading and assigning data in my table, and then changing some codebehind and at the same time binding it into the gridview.This is my Image Handler:<%@ WebHandler Language="VB" %>Imports SystemImports System.WebImports System.ConfigurationImports System.Data.SqlClientPublic Class Handler : Implements IHttpHandler        Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest        Dim con As New SqlConnection()        con.ConnectionString = ConfigurationManager.ConnectionStrings("automotiveConnectionString").ConnectionString                ' Create SQL Command           &n

    how do i use javascript to change values of controls inside a gridview

    i have 2 labels (lblRate,lblTotal) and a textbox (txtQuantity) in a itemtemplate of a gridview.I want to calculate the products of rate and quantity and show it in Total as the textbox loses focus...i cant use textchanged because i dont want the page to postback.How do i use javascript to achieve this??Please Help Urgently....<asp:TemplateField HeaderText="Rate">                <ItemTemplate>                    <asp:Label ID="lblRate" runat="server" Text='<%# Eval("Rate") %>' />                </ItemTemplate>            </asp:TemplateField> <asp:TemplateField HeaderText="Quantity">                <ItemTemplate>                    <asp:TextBox ID="txtQty" runat="server" />                </ItemTemplate>&

    Binding byte[] to image control in navigation application leaks

    Hi there, I have a (minimal) navigation application with two pages. Page1 contains an image. Switching between pages is done via a buttonhandler in code behind, for instance, (this.NavigationService.Navigate(new Page2())) The image is loaded in code behind via: private void LoadImage() { string fileName = "./images/image.bmp"; if (!new FileInfo(fileName).Exists) throw new Exception("File name doesn't exist"); using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { this.ImageData2 = new byte[fs.Length]; fs.Read(this.ImageData2, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); } } ImageData2 is a byte[] property that sends a propertychange event on changing. ImageData2 is bound to an image in xaml: <Image Grid.Row="1" Source="{Binding Path=ImageData2, Mode=OneTime}"/> When we unload Page1 the following clean up code is executed private void Page_Unloaded(object sender, RoutedEventArgs e) { this.ImageData2 = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } Now, when I start changing pages, I expect the Page we leave to unload, so the GC removes the byte array. However, it doesn't. Am I missing something? Binding the image to a BitmapImage (ImageData1, as you might have guessed:-) ) doesn't leak.

    Display image icon in HyperLinkField of Gridview

     Hello everyone! Can someone please tell me how to display an image in a HyperLinkField of a gridview?  Instead of words, I just want to show a simple little icon that can be clicked on and pass a query string to the next page.  The first hyperlink field I have set up works perfectly and passes the querystring to the next page.   The second hyperlinkfield is my attempt at showing the image but it's giving me a squiggly and telling me "the element img cannot be nested within the element hyperlinkfield" I got this technique from this brief article   - I would like to accomplish exactly what it says it is suppose to do. Thanks!   <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="clientID"> <Columns> <asp:BoundField DataField="clientFirstName" HeaderText="First Name" /> <asp:BoundField DataField="clientLastName" HeaderText="Last Name" /> <asp:HyperLinkField HeaderText="More Info" Text="View more info..." DataNavigateUrlFields="clientID" DataNavigateUrlFormatString="Cli

    Image In Gridview!

    1- How can i upload and show an image file for the customer in his account details page when the information are showing to him by  a gridview?2- What is most commonly use as a data control for customer account pages (gridview or detailsview)?Regards.

    How to disable fields in a GridView when you change the listbox options?

     Hi all I am trying to apply the same logic I applied to a FormView. Here is what I do:I have a DropDownListBox as one of my FormView fields and when I choose a specific option the fields inside my FormView are enabled/disabled according to the options chosen. Well I havent been able to apply that concept to a GridView. Here is my code to the FormView:protected void ItemFormView_DataBound(object sender, EventArgs e) { DropDownList ddlConfigType = ItemFormView.FindControl("ddlConfigTypes") as DropDownList; if (ddlConfigType != null) { if (ItemFormView.CurrentMode == FormViewMode.Edit) { DisableNAFields_EditMode(ddlConfigType.SelectedItem.Text); } } }private void DisableNAFields_EditMode(string configType) { TextBox txtboxScope = ItemFormView.FindControl("txtboxScope") as TextBox; if (configType == "registry") { txtboxScope.Enabled = false; } } Is there a GridView mode enumeration? How do I achieve the same goal? Thank you
    ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
    Sql Server  SharePoint  Silverlight  Others  All   

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend