如何在表的每一行中显示常用按钮 [英] How to show common buttons in every row of a table

查看:74
本文介绍了如何在表的每一行中显示常用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建了一个员工表,现在我已经创建了一个asp网页,因为我只想显示emplouee ID,而且除了我想要显示的每一列中的接受并且拒绝按钮。请告诉我sinple解决方案,因为我是.NET新手。

解决方案

你可以使用ButtonFiled,

探索如何:响应GridView中的按钮事件控制 [ ^ ]


一个简单的例子。



GridView aspx页面中的标记

 <   asp:GridView     ID   =  grdEmployee  

runat = server

< span class =code-attribute> DataKeyNames = id

AutoGenerateColumns = 错误

OnRowCommand = grdEmployee_OnRowCommand >
< >
< asp:BoundField DataField = name HeaderText = 名称 / >
< asp:BoundField DataField = email HeaderText < span class =code-keyword> = 电子邮件 / >
< asp:TemplateField ShowHeader = 错误 >
< ItemTemplate >
< asp:按钮 ID = btnAccept runat = server CausesValidation = false CommandName = 接受 文本 = 接受 CommandArgument =' <% #Eval( id%> ' / >
< / ItemTemplate >
< / asp:TemplateField >
< asp:TemplateField ShowHeader = False >
< ItemTemplate < span class =code-keyword>>
< asp:Button ID = btnReject runat = server CausesValidation = false CommandName = 拒绝 文字 = 拒绝 CommandArgument =' <% #Eval( id%> ' / >
< / ItemTemplate >
< / asp:TemplateField >
< /列 >
< / asp:GridView >



CodeBehind for grdEmployee_OnRowCommand

  protected   void  grdEmployee_OnRowCommand( object  sender,GridViewCommandEventArgs e)
{
int empID = 0 ;

// 从CommandArgument获取员工ID
empID = Convert.ToInt32(e.CommandArgument);

// 接受
if (e.CommandName!= 接受
{
// 执行接受任务/ logic在这里使用变量empID ...
}

// 对于拒绝
如果(e.CommandName!= 拒绝
{
// 使用变量empID执行拒绝任务/逻辑...
}
}


I have a created an employee table,and now i have created a asp web page ,in that i want to display only emplouee ids and in addition to that in every column i want to display Accept and Reject buttons.Please tell me sinple solution as i am new to .NET .

解决方案

You can use ButtonFiled for that,
explore How to: Respond to Button Events in a GridView Control[^]


One simple example for you.

GridView Markup in aspx page

<asp:GridView ID="grdEmployee"

              runat="server"

              DataKeyNames="id"

              AutoGenerateColumns="False"

              OnRowCommand="grdEmployee_OnRowCommand">
    <Columns>
        <asp:BoundField DataField="name" HeaderText="Name" />
        <asp:BoundField DataField="email" HeaderText="Email" />
        <asp:TemplateField ShowHeader="False">
            <ItemTemplate>
                <asp:Button ID="btnAccept" runat="server" CausesValidation="false" CommandName="Accept" Text="Accept" CommandArgument='<%# Eval("id") %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField ShowHeader="False">
            <ItemTemplate>
                <asp:Button ID="btnReject" runat="server" CausesValidation="false" CommandName="Reject" Text="Reject" CommandArgument='<%# Eval("id") %>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>


CodeBehind for grdEmployee_OnRowCommand

protected void grdEmployee_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
      int empID = 0;

      // Get the Employee ID from the CommandArgument
      empID = Convert.ToInt32(e.CommandArgument);

      // For Accept
      if (e.CommandName != "Accept")
      {
           // Do your Accept task/logic here using the variable empID...
      }

      // For Reject
      if (e.CommandName != "Reject")
      {
           // Do your Reject task/logic here using the variable empID...
      }
}


这篇关于如何在表的每一行中显示常用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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