<div>
<table>
<tr>
<td>
<asp:Label runat="server" text="Search"></asp:Label>
</td>
<td>
<asp:TextBox runat="Server" placeholder="Enter EmpId" id="txtSearch">
</asp:TextBox>
</td>
<td>
<asp:Button ID="btnGo" runat="server" Text="Go" onclick="btnGo_Click"/>
</td>
<td>
<asp:Button ID="btnShowAll" runat="server" Text="ShowAll"
onclick="btnShowAll_Click" />
</td>
</tr>
</table>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText="EmpId" DataField="EmpId"/>
<asp:BoundField HeaderText="Employee Name" DataField="EmpName"/>
<asp:BoundField HeaderText="Designation" DataField="EmpDesgn"/>
<asp:BoundField HeaderText="Salary" DataField="Sal"/>
<asp:TemplateField HeaderText="Salary Status">
<ItemTemplate>
<asp:Button runat="Server" id="btnPay" text="Pay" CommandName="Pay"
Visible='<%#Eval("Status").Equals("Paid")?false:true %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
我想在点击付款按钮时支付未付员工的工资,因为付款按钮仅显示未付工资。
答案 0 :(得分:0)
您可以使用OnRowCommand事件执行此操作。将事件处理程序添加到gridview
OnRowCommand="GridView1_RowCommand"
将命令参数绑定到按钮
<asp:TemplateField HeaderText="Salary Status">
<ItemTemplate>
<asp:Button runat="Server" id="btnPay" text="Pay" CommandName="Pay"
Visible='<%#Eval("Status").Equals("Paid")?false:true %>'
CommandArgument = '<%#Eval("EmpId")%>'
/>
</ItemTemplate>
</asp:TemplateField>
然后在RowCommand事件中,您可以从命令参数中捕获EmpId,支付薪水并重新绑定网格视图
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName=="Pay")
{
// get the command argument.
string empId = e.CommandArgument as string;
//you code here to pay the salary
//ReBind Gridview to refresh
}
}