i have the below gridview code in my asp.net c# page. Problem is i having an error saying that "A field or property with the name 'ProfileID, Image' was not found on the selected data source.". This ProfileID and Image column is available in the database table. I not sure why the gridview can't find it.
Expand|Select|Wrap|Line Numbers
- <asp:GridView ID="gridview_myphoto" runat="server" AutoGenerateColumns="False" Width="100%">
- <Columns>
- <asp:ImageField HeaderText="Picture" DataImageUrlField="ProfileID, Image" DataImageUrlFormatString="Image/ProfileImage/{0}/{1}">
- <HeaderStyle Width="35px" />
- </asp:ImageField>
- <asp:TemplateField>
- <HeaderTemplate>
- Caption
- </HeaderTemplate>
- <HeaderStyle Width="250px" />
- <ItemTemplate>
- <asp:TextBox ID="txt_imgcaption" runat="server" Text='<%# Eval("Caption") %>' ></asp:TextBox>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField>
- <HeaderStyle Width="200px"/>
- <ItemStyle HorizontalAlign=Center />
- <ItemTemplate>
- <asp:Button ID="but_setmainpage" runat="server" Text="Set Main Image" /><br />
- <asp:Button ID="but_updcaption" runat="server" Text="Update Caption" /><br />
- <asp:Button ID="but_remove" runat="server" Text="Remove" />
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- <AlternatingRowStyle BackColor="#E0E0E0" />
- </asp:GridView>
// MY CODE-BEHIND FOR GRIDVIEW
Expand|Select|Wrap|Line Numbers
- protected void link_managemyphoto_Click(object sender, EventArgs e)
- {
- string myuserid = "1111";
- SqlConnection sqlconn2 = new SqlConnection("server=blabla;uid=sa;pwd=server;database=Profile");
- sqlconn2.Open();
- SqlCommand sqlcomm2 = new SqlCommand();
- sqlcomm2.Connection = sqlconn2;
- sqlcomm2.CommandText = "SELECT ProfileID, Image FROM MyImage WHERE ProfileID = @userid";
- sqlcomm2.Parameters.AddWithValue("@userid", myuserid);
- SqlDataReader sqldatareader2 = sqlcomm2.ExecuteReader();
- gridview_myphoto.DataSource = sqldatareader2;
- gridview_myphoto.DataBind();
- sqldatareader2.Close();
- sqlconn2.Close();
- }
- }
Thx.