onrowcancelingedit="GridView1_RowCancelingEdit" DataKeyNames="RollMessageID" 
        onrowediting
="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating">
        
<Columns>
            
<asp:BoundField DataField="RollMessageID" HeaderText="编号" Visible="False" />
            
<asp:BoundField DataField="Heading" HeaderText="姓名" />
            
<asp:CommandField ShowEditButton="True" />
        
</Columns>
    
</asp:GridView>

//后台:

         
protected void Page_Load(object sender, EventArgs e)
        {
            
if (!IsPostBack)
            {
                BindDataInfo();
            }

        }

//绑定数据
        protected void BindDataInfo()
        {
            RollMessageBusiness rm 
= new RollMessageBusiness();
            GridView1.DataSource 
= rm.GetAllRollMessage();
            GridView1.DataBind();
        }

//编辑按钮

        
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex 
= e.NewEditIndex;
            BindDataInfo();
        }

//更新按钮

        
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            
string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
            
string strhead = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;

            RollMessageBusiness rmb 
= new RollMessageBusiness();
            rmb.UpdateRollMessage(id, strhead);
            GridView1.EditIndex 
= -1;
            BindDataInfo();
        }

//取消按钮

        
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex 
= -1;
            BindDataInfo();
        }

相关文章:

  • 2022-12-23
  • 2021-09-06
  • 2022-12-23
  • 2021-09-11
  • 2021-07-20
  • 2022-03-10
  • 2021-08-27
猜你喜欢
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
相关资源
相似解决方案