首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

[再一次_]DataGrid 更新时取得绑定列的有关问题。附代码。有关问题是取不到值。多谢。难道有关问题很大吗

2012-01-18 
[再一次_求助]DataGrid 更新时取得绑定列的问题。附代码。问题是取不到值。谢谢。难道问题很大吗。这是更新代码

[再一次_求助]DataGrid 更新时取得绑定列的问题。附代码。问题是取不到值。谢谢。难道问题很大吗。
这是更新代码:
        protected   void   DataGrid_Upadte(object   source,   DataGridCommandEventArgs   e)
        {
                try
                {
                        con.Open();
                        string   sqlUpdate   =   "update   Power   set   PowerName=@PowerName,PowerLink=@PowerLink   where   PowerID=@PowerID ";
                        SqlCommand   com   =   new   SqlCommand(sqlUpdate,   con);
                        com.Parameters.Add(new   SqlParameter( "@PowerName ",   SqlDbType.VarChar,   50));
                        com.Parameters.Add(new   SqlParameter( "@PowerLink ",   SqlDbType.VarChar,   100));
                        com.Parameters.Add(new   SqlParameter( "@PowerID ",SqlDbType.Int));
                        com.Parameters[ "@PowerName "].Value   =((TextBox)(e.Item.Cells[2].Controls[0])).Text;//注:要是把“SSS”等字符串赋予它就可以写入
                        com.Parameters[ "@PowerLink "].Value   =((TextBox)(e.Item.Cells[3].Controls[0])).Text;//注:要是把“SSS”等字符串赋予它就可以写入                         com.Parameters[ "@PowerID "].Value   =   Dg_Edit.DataKeys[(int)e.Item.ItemIndex];
                        com.ExecuteNonQuery();
                        string   s   =   com.CommandText;
                        Dg_Edit.EditItemIndex   =   -1;
                }
                catch   (Exception   ex)
                {
                        Response.Write(ex.ToString());
                }
                finally
                {
                        if   (con.State   !=   ConnectionState.Closed)
                                con.Close();
                }
                dataBindToDataGrid();
        }
下面是datagrid的代码:
<asp:DataGrid   ID= "Dg_Edit "   runat= "server "   AutoGenerateColumns= "False "   DataKeyField= "PowerID "   OnDeleteCommand= "DataGrid_DeleteCommand "   OnEditCommand= "DataGrid_Edit "   OnCancelCommand= "DataGrid_Cancel "   OnUpdateCommand= "DataGrid_Upadte ">


                                                                                                                <Columns>
                                                                                                                        <asp:BoundColumn   DataField= "PowerID "   HeaderText= "PowerID "   ReadOnly= "True "> </asp:BoundColumn>
                                                                                                                        <asp:BoundColumn   DataField= "PowerCode "   HeaderText= "PowerCode "   ReadOnly= "True "> </asp:BoundColumn>
                                                                                                                        <asp:BoundColumn   DataField= "PowerName "   HeaderText= "PowerName "> </asp:BoundColumn>
                                                                                                                        <asp:BoundColumn   DataField= "PowerLink "   HeaderText= "PowerLink "> </asp:BoundColumn>
                                                                                                                        <asp:EditCommandColumn   CancelText= "取消 "   EditText= "编辑 "   UpdateText= "更新 "> </asp:EditCommandColumn>
                                                                                                                        <asp:ButtonColumn   CommandName= "Delete "   Text= "删除 "> </asp:ButtonColumn>


                                                                                                                </Columns>
                                                                                                        </asp:DataGrid>
实际上昨晚在   http://community.csdn.net/Expert/topic/5478/5478998.xml?temp=.9544031   就问过。没有人回答。正解者,前去领分。

[解决办法]
没有错误的提示?
[解决办法]
我不会,但是我顶你

热点排行
Bad Request.