How to apply Image URL to Image in gridview in for loop in C#

Source
<asp:GridView ID=”GridView1″ DataKeyNames=”NMP_Image_ID” runat=”server” AutoGenerateColumns=”False”
RowStyle-HorizontalAlign=”Center” OnRowDeleting=”GridView1_RowDeleting” OnRowEditing=”GridView1_RowEditing”
Width=”775px” AllowPaging=”True” Height=”10px” OnPageIndexChanging=”GridView1_PageIndexChanging”
PageSize=”15″ OnRowCommand=”GridView1_RowCommand”>
<Columns>
.
.
.
 <asp:TemplateField HeaderText=”Image Icon”>
<ItemTemplate>
<asp:ImageButton ID=”Image1″ runat=”server” Height=”40″ Width=”40″ Visible=”true” CommandArgument=’<% #des(Eval(“NMP_Image_Id”).ToString()) %>’ CommandName=”SingleImage” />
</ItemTemplate>
</asp:TemplateField>
.
.
.
 </Columns>
</asp:GridView>
.CS code
 protected void bindtogrid()
{
connectionObj = new SqlConnection(conString);
connectionObj.Open();
commandObj = new SqlCommand(“select * from NMP_Page_Content where NMP_Content_Type=’Image’ order by ‘NMP_Screen_Name’”, connectionObj);
tableObj = new DataTable();
adapterObj = new SqlDataAdapter(commandObj);
adapterObj.Fill(tableObj);
GridView1.DataSource = tableObj;
GridView1.DataBind();
Image imageObject;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
imageObject = (Image)GridView1.Rows[i].Cells[9].FindControl(“Image1″);
imageObject.ImageUrl = tableObj.Rows[i]["NMP_Image_File_Path"].ToString();
}
}

Comments