【发布时间】:2012-08-22 14:54:39
【问题描述】:
我对asp.net比较陌生。所以如果我的问题很幼稚,请多多包涵 我的网格设计:
<asp:GridView runat ="server" GridLines = "Both" DataKeyNames="book_id"AutoGenerateColumns ="false" CellPadding ="5" CellSpacing ="5" allowpaging="True" allowsorting="True"
ID="gv_table1" EmptyDataText ="No data exists" OnRowEditing="gv_RowEditing"
OnRowCancelingEdit="gv_RowCancelingEdit" OnRowUpdating="gv_RowUpdating" OnRowDeleting="gv_RowDeleting">
<Columns>
<asp:BoundField HeaderText="Book ID" DataField="book_id">
</asp:BoundField>
<asp:BoundField DataField="book_name" HeaderText="Book Name">
</asp:BoundField>
<asp:BoundField DataField="author_name" HeaderText="Author Name">
</asp:BoundField>
<asp:BoundField DataField="publisher" HeaderText="Publisher">
</asp:BoundField>
<asp:BoundField DataField="year_edition" HeaderText="Year/Edition">
</asp:BoundField>
<asp:BoundField DataField="total_no" HeaderText="Total No">
</asp:BoundField>
<asp:BoundField DataField="available" HeaderText="Available">
</asp:BoundField>
<asp:BoundField DataField="tags" HeaderText="Tags">
</asp:BoundField>
<asp:BoundField DataField="fare" HeaderText="Fare">
</asp:BoundField>
<asp:BoundField DataField="state" HeaderText="State">
</asp:BoundField>
<asp:templatefield HeaderText ="Options">
<itemtemplate >
<asp:linkbutton id="btnEdit" runat="server" commandname="Edit" text="Edit" />
<asp:linkbutton id="btnDelete" runat="server" commandname="Delete" text="Delete" />
</itemtemplate>
<edititemtemplate>
<asp:linkbutton id="btnUpdate" runat="server" commandname="Update" text="Update" />
<asp:linkbutton id="btnCancel" runat="server" commandname="Cancel" text="Cancel" />
</edititemtemplate>
</asp:templatefield>
</Columns>
</asp:GridView>
我的代码:
public void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int bookid = Convert.ToInt32(gv_table1.DataKeys[e.RowIndex].Values["book_id"].ToString());
string bookname =(gv_table1.Rows[e.NewValues].Cells[1].Controls[0] as TextBox).Text;
string bookname = (gv_table1.Rows[e.RowIndex].FindControl("author_name") as TextBox).Text;
string book = gv_table1.Rows[e.RowIndex].Cells[1].Text ;
}
我可以删除但不能编辑数据。我无法获得我在网格视图中输入的更改值。我尽最大努力让我在编辑或更改之前获得了网格视图中的值。 提前感谢朋友们。
【问题讨论】:
-
最好的方法是将你的逻辑封装在try catch块中,然后开始在visual studio中调试你的项目,只有这样你才能解决问题
-
检查我的更新答案我得到了解决方案。