【已解决】GridView自带编辑无法取得修改后的数据
<asp:GridView ID="ArticleList" runat="server" CellPadding="4" ForeColor="Black" GridLines="Vertical" Width="100%" AutoGenerateColumns="False"
onrowcancelingedit="ArticleList_RowCancelingEdit"
onrowdeleting="ArticleList_RowDeleting" onrowediting="ArticleList_RowEditing"
onrowupdating="ArticleList_RowUpdating" BackColor="White"
BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
DataKeyNames="CustomerID">
<FooterStyle BackColor="#CCCC99" />
<RowStyle BackColor="#F7F7DE" />
<Columns>
<asp:BoundField DataField="CustomerName" HeaderText="用户姓名" />
<asp:BoundField DataField="CustomerSex" HeaderText="用户性别" />
<asp:BoundField DataField="Address" HeaderText="家庭住址" />
<asp:BoundField DataField="CustomerTel" HeaderText="联系电话" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowSelectButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
protected void ArticleList_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string CustomerID = this.ArticleList.DataKeys[e.RowIndex][0].ToString();
string CustomerName = ((TextBox)(this.ArticleList.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim();
string CustomerSex = ((TextBox)(this.ArticleList.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
string Address = ((TextBox)(this.ArticleList.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
string CustomerTel = ((TextBox)(this.ArticleList.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
UpdateCus(CustomerID, CustomerName, CustomerSex, CustomerTel, Address);
this.ArticleList.EditIndex = -1;
getlist();
}
public void UpdateCus(string CustomerID, string CustomerName, string CustomerSex, string CustomerTel, string Address)
{
try
{
OpenConnection();
= CommandType.Text;
= "Update [Customer] Set CustomerName = '" + CustomerName + "', CustomerSex = " + CustomerSex + ", CustomerTel = '" + CustomerTel + "', Address = '" + Address + "' where CustomerID = " + CustomerID + "";
comm.ExecuteNonQuery();
}
catch (Exception x)
{
Response.Write(x.Message);
}
finally
{
CloseConnection();
}
}
CustomerName, CustomerSex, CustomerTel, Address都取得是输出数据,而无法取得编辑表单中的数据是什么原因呢?
[ 本帖最后由 zhangyao3287 于 2010-1-20 13:51 编辑 ]