在gridview中添加了按钮,但我无法获取其事件,该按钮用于添加新行 [英] Added button in gridview but i unable to get their events the button is used to add new rows

查看:74
本文介绍了在gridview中添加了按钮,但我无法获取其事件,该按钮用于添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的

我正在尝试在按钮单击上添加行
该按钮在datagridview中
像这样添加

Dear

I am trying to get add the rows on button click
the button is in datagridview
it is added like this

<asp:TemplateField>
   <FooterTemplate>
       <asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" 

           CommandName="AddNewRow" />
   </FooterTemplate>
</asp:TemplateField>



但是我无法获得此按钮的事件
我应该使用什么事件

单击该按钮即可正常工作

谢谢
请使用GridView行命令事件重播



But I am unable get events of this button
what event should i use

to work when i click that button

thank you
please replay

推荐答案

尝试.
'On GridView Row Command Event..

If e.CommandSource="AddNewRow" Then
  'Add New Row to GridView.
End IF


在此按钮之外添加此按钮网格.当您单击添加按钮,然后将gridview行存储到另一个数据表中时,绑定时在底部添加一个空行.像这样:

Add this button outside of grid. when u''ll click on add button then store gridview rows into some another datatable and when bind that then add one empty row in the bottom. like this :

protected void addnew_Click(object sender, ImageClickEventArgs e)
    {
        grdMain.DataSource = FillDataTable(grdMain.Rows.Count + 1, "ADD", 0);
        grdMain.DataBind();
    }

public DataTable FillDataTable(int _rowCount, string _type, int _id)
    {
        DataTable _dtBands = ((DataTable)ViewState["item"]).Clone();

        DataRow row;
        if (_type == "ADD")
        {
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {
                row = _dtBands.NewRow();
                row["Item"] = ((DropDownList)grdMain.Rows[i].FindControl("ddlItemName")).SelectedValue.ToString();
                row["Item_id"] = ((HiddenField)grdMain.Rows[i].FindControl("hdnitemid")).Value;
                
                _dtBands.Rows.Add(row);
            }

            row = _dtBands.NewRow();
            row["Item"] = "";
            row["Item_Id"] = "";
            
            _dtBands.Rows.Add(row);
        }
        else if (_type == "REMOVE")
        {
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {
                if (i + 1 != _id)
                {
                    row = _dtBands.NewRow();

                    row["Item"] = ((DropDownList)grdMain.Rows[i].FindControl("ddlItemName")).SelectedValue.ToString();
                    row["item_id"] = ((HiddenField)grdMain.Rows[i].FindControl("hdnitemid")).Value;
                    
                    _dtBands.Rows.Add(row);
                }
            }
        }
        else
        {
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {
                
                    row = _dtBands.NewRow();

                    row["Item"] = ((DropDownList)grdMain.Rows[i].FindControl("ddlItemName")).SelectedValue.ToString();
                    row["Item_Id"] = ((HiddenField)grdMain.Rows[i].FindControl("hdnitemid")).Value;
                  
                    _dtBands.Rows.Add(row);
           }
        }
        return _dtBands;
    }



使用这个可以做到这一点.
希望对您有帮助.
如果有帮助,请不要忘记将其标记为答案. :)



using this you can do this.
Hope this will help you.
Don''t forget to mark as answer if it helps. :)


检查

Check

if (e.CommandName.Equals("AddNewRow"))
{
   //Write Code Here
}


在Gridview的 RowCommand 事件上.


on RowCommand event of Gridview.


这篇关于在gridview中添加了按钮,但我无法获取其事件,该按钮用于添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆