DataGrid中更新BoundColumn,点修改,在文本框中输入内容,点更新,可是数据库中相应字段为空,我开始以为是定位错了,把e.Item.Cells[1].Text中从0到3都试了,也不行(4就溢出了),代码如下:
public void datagridBak_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)//更新记录
{
SqlConnection myConnection=new SqlConnection(common_cs.database.connectionstr);
myConnection.Open();
string strBound=e.Item.Cells[1].Text;
string strupd="update JSB set jsmc='"+strBound+"' where jsid='"+datagridBak.DataKeys[e.Item.ItemIndex]+"'";
SqlCommand myCommand=new SqlCommand(strupd,myConnection);
SqlDataReader myReader=myCommand.ExecuteReader();
myReader.Close();
myConnection.Close();
}
DataGrid中的列:
<Columns>
<asp:BoundColumn Visible="False" DataField="jsid" HeaderText="id">
<HeaderStyle Height="25px" Width="10%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="jsmc" HeaderText="名称"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="更新" HeaderText="编辑" CancelText="取消" EditText="修改">
<HeaderStyle Width="20%"></HeaderStyle>
</asp:EditCommandColumn>
<asp:ButtonColumn Text="X" ButtonType="PushButton" HeaderText="删除" CommandName="delete">
<HeaderStyle Width="7%"></HeaderStyle>
</asp:ButtonColumn>
</Columns>
为什么呢???请前辈指点,谢谢