Gridview按钮事件 [英] Gridview Button Event
本文介绍了Gridview按钮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个gridview,因为在单击事件上有两个按钮,我必须找出Datakey值和每个单元格的值.
以下是ASPX中的代码
Hi All,
I have a gridview in that I have two buttons on click event I have to find out Datakey value and values of each cells.
Following is the code in ASPX
<asp:GridView ID="GRVLeaveRequest" runat="server" AutoGenerateColumns="False"
CellPadding="4" Font-Names="Verdana" Font-Size="X-Small" ForeColor="#000099"
GridLines="None" DataKeyNames="OfficialEmail">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField HeaderText="Employee Name" ItemStyle-HorizontalAlign="Center" DataField="EmployeeName" />
<asp:BoundField HeaderText="Date From" ItemStyle-HorizontalAlign="Center" DataField="Startdate" />
<asp:BoundField HeaderText="Date To" ItemStyle-HorizontalAlign="Center" DataField="Endate" />
<asp:BoundField HeaderText="No of Leave Available" ItemStyle-HorizontalAlign="Center" DataField="Leaves" />
<asp:TemplateField HeaderText="Approve">
<ItemTemplate>
<asp:Button ID="btnApprove" Height="25px" ForeColor="Navy" Font-Size="X-Small" OnClick="btnApprove_Click" Font-Names="Verdana" runat="server" Text="Approve" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dis-Approve">
<ItemTemplate>
<asp:Button ID="btnDisApprove" Height="25px" ForeColor="Navy" Font-Size="X-Small" OnClick="btnDisApprove_Click" Font-Names="Verdana" runat="server" Text="Dis-Approve" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
//*********************************//
在后面的代码中做了类似的事情
//*********************************//
and in code code behind did something like it
protected void btnApprove_Click(object sender, EventArgs e)
{
foreach (GridViewRow grd in GRVLeaveRequest.Rows)
{
/*Here I have to find out datakey value and each cells value*/
}
}
请帮助我解决我的问题.非常感谢您
人.
在此先谢谢您.
Please help me in sorting out my problem .I will be very thankful to you
People.
Thanks in advance.
推荐答案
要查找该行的单元格值,您需要先找到按钮的容器行.
参见此 [ ^ ]肯定会为您提供帮助.
[更新]
现在,您从链接的文章中获得了GridViewRow(grdRow)的对象.
您可以像下面那样进一步调查,以找到有关Button click事件的数据键
for finding cell values of that row you need to find container row of button first.
See THIS[^] will surely help you.
[update]
As you now got object of GridViewRow(grdRow) from linked article.
you could further investigate like below to find datakey on Button click event
GridViewName.DataKeys[grdRow.RowIndex].Value.toString();
如果每一行都存在按钮,则不需要遍历每一行.
you do not need to loop through each row if button is present for every row.
foreach(GridView1.Rows中的GridViewRow行)
{
int _dkname = Convert.ToInt32(GridView1.DataKeys [row.RowIndex] .Value);
}
foreach (GridViewRow row in GridView1.Rows)
{
int _dkname = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
}
这篇关于Gridview按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文