datagrid更新、修改和取消代码

7 篇文章 0 订阅
 
private   void  dg_infoKind_CancelCommand( object  source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            dg_infoKind.EditItemIndex 
=   - 1 ;
            
this .bindGrid();
        }

        
private   void  dg_infoKind_EditCommand( object  source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            
this .dg_infoKind.EditItemIndex = e.Item.ItemIndex;
            
this .bindGrid();
        }

        
private   void  dg_infoKind_ItemCommand( object  source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            
try
            {
                
if (e.CommandName  ==   " delete " )
                {
                    
if (dType.Delete(dg_infoKind.DataKeys[e.Item.ItemIndex].ToString()))
                    {
                        
this .lbl_message.Text  =   " 删除成功! " ;
                        
this .lbl_message.ForeColor  =  Color.Green;
                        
this .bindGrid();
                    }
                    
else
                    {
                        
this .lbl_message.Text  =   " 删除失败! " ;
                        
this .lbl_message.ForeColor  =  Color.Red;
                    }
                }
            }
            
catch
            {
                
this .lbl_message.Text  =   " 删除失败!此项在本系统其他地方引用,请先删除! " ;
                
this .lbl_message.ForeColor  =  Color.Red;
            }
        }

        
private   void  dg_infoKind_ItemDataBound( object  sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            
if (e.Item.ItemType  !=  ListItemType.Footer  &&  e.Item.ItemType  !=  ListItemType.Header)
                e.Item.Cells[
3 ].Attributes.Add( " onclick " , " return confirm('你将删除这条记录,是否继续?'); " );
        }

        
private   void  dg_infoKind_UpdateCommand( object  source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            
try
            {
                
string  id  =  dg_infoKind.DataKeys[e.Item.ItemIndex].ToString();
                
string  Name  =  ((TextBox)(e.Item.Cells[ 1 ].Controls[ 0 ])).Text;
             

                 if (dType.Update(id,Name))
                {
                    
this .lbl_message.Text  =   " 修改成功! " ;
                    
this .lbl_message.ForeColor  =  Color.Green;
                    dg_infoKind.EditItemIndex 
=   - 1 ;
                    
this .bindGrid();
                }
                
else
                {
                    
this .lbl_message.Text  =   " 修改失败! " ;
                    
this .lbl_message.ForeColor  =  Color.Red;
                }
            }
            
catch
            {
                
this .lbl_message.Text  =   " 修改失败! " ;
                
this .lbl_message.ForeColor  =  Color.Red;
            }
        }

 为dropdownlist赋值:

html代码:

< asp:DropDownList  id =DropDownList2  runat ="server"  Width ="100px"  SelectedValue ='<%#  DataBinder.Eval(Container, "DataItem.userType") % > '>
                                            
< asp:Label  id =Label1  runat ="server"  Text ='<%#  DataBinder.Eval(Container, "DataItem.typeName")% > '>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值