我有一个GridView与一个ObjectDataSource,我想单击更新。 因此,gridview加载可编辑和固定的字段。 我循环浏览gridview以全部更新。 我能够从固定字段(单元格[0])加载到Products对象(p.ProductID),但我无法从可编辑字段中加载值(单元格[1 ])转换为Products对象(p.Productname)。如何在Gridview中获取可编辑字段的值
如何在对象中获取此值,以便我可以将该对象发送给BLL方法。 如何row.Cells [0] .Text适用于固定字段,但不适用于可编辑字段?
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);
}
}
标记:
<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>
这将是人们想,如果你提供你的标记的相关部分来回答你的问题是非常有用的。 – jadarnel27 2012-04-11 12:45:19