GridView里有个列,我在里面用了一个 LinkButton
<asp:TemplateField HeaderText="员工">
<HeaderStyle HorizontalAlign="Left" Width="50px" />
<ItemTemplate>
<asp:LinkButton ID="lbtnyg" runat="server" CommandArgument='<%# Eval("id") %>' OnClick="lbtnyg_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
我知道可以获取 LinkButton的CommandArgument,可是我还需要一个参数,所以我在GridView的 DataKeyNames="id,name"设置了两个参数
protected void lbtnyg_Click(object sender, EventArgs e)
{ int area = Convert.ToInt32(((LinkButton)(sender)).CommandArgument); }
我希望能在 lbtnyg_Click 获取 DataKeyNames的name参数,有没朋友有做过
<asp:TemplateField HeaderText="员工">
<HeaderStyle HorizontalAlign="Left" Width="50px" />
<ItemTemplate>
<asp:LinkButton ID="lbtnyg" runat="server" CommandArgument='<%# Eval("id") %>' OnClick="lbtnyg_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
我知道可以获取 LinkButton的CommandArgument,可是我还需要一个参数,所以我在GridView的 DataKeyNames="id,name"设置了两个参数
protected void lbtnyg_Click(object sender, EventArgs e)
{ int area = Convert.ToInt32(((LinkButton)(sender)).CommandArgument); }
我希望能在 lbtnyg_Click 获取 DataKeyNames的name参数,有没朋友有做过
解决方案 »
- ASP.NET int 成员变量,仍然很困惑
- 电子商务。怎么连接银行或支付宝。。不够在加
- ASP.net封装类导出数据到EXCEL ++有需要的看看
- 急~有关于帖子调用的问题
- ImageButton中PostBackUrl属性的问题
- 请问如何找到已知记录的上一条记录和下一条记录
- 求好用的带下拉的日期控件
- 用 【REBOL】, 轻松写出第一个 CGI 程序,欢迎大家一起来学 REBOL
- TreeView问题
- TextBox中值,转换为数组的初始值
- 未将对象引用设置到对象的实例
- 装了vs2008后,怎么在控制面板中找不到.netframework3.5呢?操作系统是win2003,需要别外装什么吗?还是其它原因?
你直接用GridView 的_RowCommand事件就好了,GridView里面的任何按钮都会触发该事件
在RowCommand事件里获取值的方法:
int area = Convert.ToInt32(e.CommandArgument.ToString());
GridViewRow row = (e.CommandSource as Control).NamingContainer as GridViewRow;
string name = gridviewName.DataKeys[row.RowIndex].Values["name"].ToString();
然后在lbtnyg_click事件中 FOR循环一下找到Name
for (int i = 0; i < this.grLeaveWord.Rows.Count; i++)
{
string name= ((HiddenField)grLeaveWord.Items[i].FindControl("LnName")).Value;
}
用这种方法试试
没有row.RowIndex啊
不是加了一个隐藏域了吗
没有row.RowIndex啊
------------------------
在GridView的RowCommand事件里操作
不要用LinkButton按钮的OnClick事件处理,因为在GridView中任何按钮的Click事件都会触发GridView的RowCommand事件
具体代码:
protected void gridviewName_RowCommand(object sender, GridViewCommandEventArgs e)
{
int area = Convert.ToInt32(e.CommandArgument.ToString());
GridViewRow row = (e.CommandSource as Control).NamingContainer as GridViewRow;
string name = gridviewName.DataKeys[row.RowIndex].Values["name"].ToString;
}
====
谁说commandArgument不能绑定两个字段了?
你在获取时再字符串处理一下.
====
谁说commandArgument不能绑定两个字段了?
你在获取时再字符串处理一下.
/**************************************************
绑定 id.和name要怎么绑定啊
<asp:LinkButton ID="lbtnyg" runat="server" CommandArgument='<%# Eval("id") %>' CommandName="lbtnygOpen"></asp:LinkButton>
然后怎么获取
int area = Convert.ToInt32(((LinkButton)(sender)).CommandArgument);