如何在点击时添加datagrid列按钮进行编码? [英] how to code in added datagrid column button on click?

查看:72
本文介绍了如何在点击时添加datagrid列按钮进行编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



添加新栏目

字段类型:按钮字段

按钮类型:按钮

命令名称:SELECT



如何在Button_Click上编码?

after bounding gridview with databse.
added added new column
FIELD TYPE : BUTTON FIELD
BUTTON TYPE :BUTTON
COMMAND NAME :SELECT

How to code on that Button_Click ??

推荐答案

GridView.RowCommand事件 [ ^ ]将处理按钮点击。



您需要在GridView MarkUp中添加一个属性 onrowcommand =MyGridView_RowCommand



并在Code Behind中定义事件如下。

The GridView.RowCommand Event[^] will handle the button click.

You need to add one attribute onrowcommand="MyGridView_RowCommand" inside GridView MarkUp.

And define the Event in Code Behind as follows.
void MyGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
    if(e.CommandName=="SELECT")
    {
        // Do whatever you want to do.
    }
}



参考上面给出的MSDN链接了解更多并查看实现。


Refer the MSDN link given above to know more and see the implementations.


这是我的标记



here is my markup

<asp:gridview id="GridView1" runat="server" allowpaging="True" xmlns:asp="#unknown">
                     AutoGenerateColumns="False" DataKeyNames="op" DataSourceID="SqlDataSource1"

                     style="z-index: 1; left: 276px;font-size:24px; top: 321px; position: absolute; height: 131px; width: 717px"
                     ForeColor="White" onrowcommand="GridView1_RowCommand">
                     <columns>
                         <asp:boundfield datafield="diarycontent" headertext="diarycontent">
                             SortExpression="diarycontent" />
                         <asp:boundfield datafield="diarypass" headertext="diarypass">
                             SortExpression="diarypass" />
                         <asp:boundfield datafield="diarydate" headertext="diarydate">
                             SortExpression="diarydate" />
                         <asp:boundfield datafield="opp" headertext="page number" sortexpression="opp" />
                         <asp:buttonfield buttontype="Button" commandname="Select">
                             HeaderText="view diary page" ShowHeader="True" Text="View Diary Page" />
                     </asp:buttonfield></asp:boundfield></asp:boundfield></asp:boundfield></columns>
                 </asp:gridview>





和cs代码



and cs code

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
   {

       if (e.CommandName == "SELECT")
       {

           MessageBox.Show("hello");
       }
   }





及其无效。:(



and its not working.:(


这篇关于如何在点击时添加datagrid列按钮进行编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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