I have a gridview with an ObjectDataSource which I want to update with one click. Therefore the gridview loads with editable and fixed fields. I loop through the gridview to update all in once. I am able to load the values from the fixed fields (Cells[0]) into the Products object (p.ProductID), but I am not able to load the values from the editable fields (Cells[1]) into the Products object (p.Productname).
How can I get this value in the object so I can send the object to the BLL method. How come row.Cells[0].Text works for fixed fields, but not for editable fields?
protected void Update_Click(object sender, EventArgs e)
{
BLLProducts BLLProducts = new BLLProducts();
Products p = new Products();
foreach(GridViewRow row in GridView1.Rows)
{
p.ProductID = Convert.ToInt16(row.Cells[0].Text);
// p.Productname = row.Cells[1].Text;
BLLProducts.update(p);
}
}
Markup:
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="test">
<Columns>
<asp:BoundField DataField="ProductID"
HeaderText="ProductID" SortExpression="ProductID" />
<asp:TemplateField HeaderText="Productname" SortExpression="Productname">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Productname") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Productname") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="test" runat="server"
SelectMethod="SelectAllProducts" TypeName="BLLProducts">
</asp:ObjectDataSource>
<asp:Button ID="Button3" runat="server" onclick="Update_Click"
Text="Update All" />
</p>
</asp:Content>
which editable field you are using?
if you have used text box then you should get value like this: