我在GridView中加了几个ButtonField,他是触发哪个事件的? 我在GridView中加了几个ButtonField,他是触发哪个事件的? 怎么得到是点击了哪一列,哪一行呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 触发的是RowCommand事件,用e.CommandArgument判断行 ivws_19您好!protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int rowIndex = Int32.Parse((String)e.CommandArgument); Label2.Text = rowIndex.ToString(); }可是我这样写,点击的时候没有反应,是事件错了还是代码写错了呢? 在前台的buttonfield中加上CommandName="xxx" 在rowcommand中判断if (e.CommandName == "xxx") protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { Response.Write("<script>alert('fsafasdf')</script>"); } 就是这样点击也没有反应,是不是没有触发这个事件。 在前台的buttonfield中加上CommandName="xxx" 在rowcommand中判断if (e.CommandName == "xxx")buttonfield属性CommandName的值设成xx(随意),然后在RowCommand事件中判断一下,就像这样: protected void gvDengji_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "xx") { //执行操作 } }如果不明白,再问我! <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Height="170px" style="font-size: small" Width="960px" onselectedindexchanged="GridView1_SelectedIndexChanged"> <Columns> <asp:BoundField DataField="ARITICLEID" HeaderText="序号" SortExpression="ARITICLEID" /> <asp:BoundField DataField="USERNAME" HeaderText="发贴人" SortExpression="USERNAME" /> <asp:BoundField DataField="TITLE" HeaderText="标题" SortExpression="TITLE" /> <asp:BoundField DataField="RECALLHITS" HeaderText="回复" SortExpression="RECALLHITS" /> <asp:BoundField DataField="IP" HeaderText="IP地址" SortExpression="IP" /> <asp:BoundField DataField="IMAGEURL" HeaderText="相关图片" SortExpression="IMAGEURL" /> <asp:BoundField DataField="DATATIME" HeaderText="发贴时间" SortExpression="DATATIME" /> <asp:ButtonField CommandName="xxx" HeaderText="精品" Text="精品" /> <asp:ButtonField CommandName="yyy" HeaderText="置顶" Text="置顶" /> <asp:ButtonField CommandName="zzz" HeaderText="编辑" Text="编辑" /> <asp:ButtonField CommandName="aaa" HeaderText="删除" Text="删除" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString4 %>" ProviderName="<%$ ConnectionStrings:ConnectionString4.ProviderName %>" SelectCommand="SELECT * FROM "LGBBS_USERARITICLE" ORDER BY "DATATIME" DESC"> </asp:SqlDataSource> protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "xxx") { Response.Write("<script>alert('fsafasdf')</script>"); int rowIndex = Int32.Parse((String)e.CommandArgument); Label2.Text = rowIndex.ToString(); } } jueyingfd 这是我的代码 “精品”他就是不执行RowCommand的代码?我是个新手,搞了半天了,你帮我看看,非常感谢你。 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Height="170px" style="font-size: small" Width="960px" onselectedindexchanged="GridView1_SelectedIndexChanged"> 这里面没有调用GridView1_RowCommand这个方法!你设置一下方法先! 这里面没有调用GridView1_RowCommand这个方法!你设置一下方法先! 将前台换为弄为设计模式,点一个gridview选择属性,点一下那个闪电一样的图标就出现了gridview的方法了,打到RowCommand双击一下! 将aspx文件弄为设计模式,点一下gridview选择属性,点一下那个闪电一样的图标就出现了gridview的方法了,打到RowCommand 双击一下,方法出现于后台cs文件中,你这里已存在方法,将后面的方法设为你已有方法就可以了!现在没打错字,非常清楚了! fuda_1985 非常谢谢你,问题解决了。 Winform 中动态创建控件问题!急!! 修改 App.Config 文件中所有IP地址。 Winform 异常问题! 在ASP.NET中如何用C#语言实现通过EXCEL对数据进行批量的输入 winfrom中DataGrid问题 asp.net 连接pop服务器下载附件 我做的 一个调用 dll的方法,怎么还是不 行的,谢谢 急!用WebBrowser在繁体XP下打印不出来! 菜鸟的问题!! 在线等!!! 我在应用程序里调用dataAccess类,引用了,数据库信息在哪修改? 抓狂中。。怎样绘制动画线条、或实现类似效果?? 请教大家一个问题, 关于反射的问题,如何把字符串转成数组名
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowIndex = Int32.Parse((String)e.CommandArgument);
Label2.Text = rowIndex.ToString();
}
可是我这样写,点击的时候没有反应,是事件错了还是代码写错了呢?
在rowcommand中判断if (e.CommandName == "xxx")
{
Response.Write("<script>alert('fsafasdf')</script>");
}
就是这样点击也没有反应,是不是没有触发这个事件。
在rowcommand中判断if (e.CommandName == "xxx")
buttonfield属性CommandName的值设成xx(随意),然后在RowCommand事件中判断一下,就像这样:
protected void gvDengji_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "xx")
{
//执行操作
}
}如果不明白,再问我!
DataSourceID="SqlDataSource1" Height="170px" style="font-size: small"
Width="960px" onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="ARITICLEID" HeaderText="序号"
SortExpression="ARITICLEID" />
<asp:BoundField DataField="USERNAME" HeaderText="发贴人"
SortExpression="USERNAME" />
<asp:BoundField DataField="TITLE" HeaderText="标题" SortExpression="TITLE" />
<asp:BoundField DataField="RECALLHITS" HeaderText="回复"
SortExpression="RECALLHITS" />
<asp:BoundField DataField="IP" HeaderText="IP地址" SortExpression="IP" />
<asp:BoundField DataField="IMAGEURL" HeaderText="相关图片"
SortExpression="IMAGEURL" />
<asp:BoundField DataField="DATATIME" HeaderText="发贴时间"
SortExpression="DATATIME" />
<asp:ButtonField CommandName="xxx" HeaderText="精品" Text="精品" />
<asp:ButtonField CommandName="yyy" HeaderText="置顶" Text="置顶" />
<asp:ButtonField CommandName="zzz" HeaderText="编辑" Text="编辑" />
<asp:ButtonField CommandName="aaa" HeaderText="删除" Text="删除" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString4 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString4.ProviderName %>"
SelectCommand="SELECT * FROM "LGBBS_USERARITICLE" ORDER BY "DATATIME" DESC">
</asp:SqlDataSource>
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "xxx")
{
Response.Write("<script>alert('fsafasdf')</script>");
int rowIndex = Int32.Parse((String)e.CommandArgument);
Label2.Text = rowIndex.ToString();
}
} jueyingfd
这是我的代码 “精品”他就是不执行RowCommand的代码?
我是个新手,搞了半天了,你帮我看看,非常感谢你。
DataSourceID="SqlDataSource1" Height="170px" style="font-size: small"
Width="960px" onselectedindexchanged="GridView1_SelectedIndexChanged">
这里面没有调用GridView1_RowCommand这个方法!你设置一下方法先!
双击一下!
双击一下,方法出现于后台cs文件中,你这里已存在方法,将后面的方法设为你已有方法就可以了!
现在没打错字,非常清楚了!
非常谢谢你,问题解决了。