GridView 问题 我给一个GridView绑定了数据a b c 按钮a1 b1 c1 按钮1 a2 b2 c2 按钮2.........按钮那一列是模板列,请问如何点击按钮调用aspx.cs 中的一个方法?????????? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <asp:ButtonField ButtonType="Button" CommandName="DownLoad" Text="取得" >protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName == "DownLoad") { .... } } protected void gvwClass_RowCommand(object sender, GridViewCommandEventArgs e) { index = Convert.ToInt32(e.CommandArgument); //fundction(); } 这样行吗`?是根据数据循环就越多按妞。。不可能都CommandName 吧`哈哈我也遇到这样的问题 int row = Convert.ToInt32(e.CommandArgument); //row 就是行号 string FilePath = GridView1.DataKeys[row].Value.ToString(); beckhans 贝克汉鸭说得很清楚了. 程序报错 e.CommandArgument的值为null 你要传ID,就把 button的CommandArgument属性帮定上ID 不可能阿,e.CommandArgument是CLR负值,把你的source贴出来看看 protected void gvwClass_RowCommand(object sender, GridViewCommandEventArgs e) { index = Convert.ToInt32(e.CommandArgument); //fundction(); }在这样取就可以 “/WebSite4”应用程序中的服务器错误。--------------------------------------------------------------------------------输入字符串的格式不正确。 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.FormatException: 输入字符串的格式不正确。源错误: 行 23: if (e.CommandName == "aaa")行 24: {行 25: int row = Convert.ToInt32(e.CommandArgument); //row 就是行号行 26: TextBox1.Text = GridView1.DataKeys[row].Value.ToString();行 27: } 源文件: e:\WebSite3\WebSite4\Default.aspx.cs 行: 25 堆栈跟踪: [FormatException: 输入字符串的格式不正确。] System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2752915 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +102 System.String.System.IConvertible.ToInt32(IFormatProvider provider) +43 System.Convert.ToInt32(Object value) +25 _Default.GridView1_RowCommand(Object sender, GridViewCommandEventArgs e) in e:\WebSite3\WebSite4\Default.aspx.cs:25 System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs e) +96 System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +121 System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +163 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56 System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +119 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56 System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +107 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +178 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3837 --------------------------------------------------------------------------------版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.42 <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="aaa" Text="按钮" />C# protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "aaa") { int row = Convert.ToInt32(e.CommandArgument); //row 就是行号 //TextBox1.Text = GridView1.DataKeys[row].Value.ToString(); } } e.CommandArgument 等于 null 吧,<asp:Button ID="Button1" runat="server" CommandArgument='<%# Bind("ID") %>' Text="Button" CommandName="Up" /> 这样行吗`? 是根据数据循环就越多按妞。。不可能都CommandName 吧` 哈哈 我也遇到这样的问题 大哥,你不是说Button是GridView的魔板列吗,那应该是<asp:ButtonField ButtonType="Button" CommandName="DownLoad" Text="取得" >而你的是<asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="aaa" Text="按钮" /> 分明你的是一个普通的按钮阿 WebBrowser内控件触发事件 传值给WinFrom处理 asp.net 怎样获得xml节点值 在页面中实现文件下载链接 checklistbox 排序,tip(40分全给正解者) 不同文件间的类怎么继承? 已按步骤安装,为何会出错??? 如何得到这个程序的cpu使用率????????? html控件作为服务器端空间运行后class属性如何在后台动态的写 怎样实现登录后,又重新回到登录页 请帮我解释一下这条SQL语句: gridview在编辑时无法获的主键的值 谁知道那儿有好用的ASP.NET(c#)+access论坛源代码下载?
{
try
{
if (e.CommandName == "DownLoad")
{
....
}
}
{
index = Convert.ToInt32(e.CommandArgument);
//fundction();
}
是根据数据循环就越多按妞。。不可能都CommandName 吧`
哈哈
我也遇到这样的问题
string FilePath = GridView1.DataKeys[row].Value.ToString();
贝克汉鸭说得很清楚了.
e.CommandArgument的值为null
{
index = Convert.ToInt32(e.CommandArgument);
//fundction();
}
在这样取就可以
--------------------------------------------------------------------------------输入字符串的格式不正确。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.FormatException: 输入字符串的格式不正确。源错误:
行 23: if (e.CommandName == "aaa")
行 24: {
行 25: int row = Convert.ToInt32(e.CommandArgument); //row 就是行号
行 26: TextBox1.Text = GridView1.DataKeys[row].Value.ToString();
行 27: }
源文件: e:\WebSite3\WebSite4\Default.aspx.cs 行: 25 堆栈跟踪:
[FormatException: 输入字符串的格式不正确。]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2752915
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +102
System.String.System.IConvertible.ToInt32(IFormatProvider provider) +43
System.Convert.ToInt32(Object value) +25
_Default.GridView1_RowCommand(Object sender, GridViewCommandEventArgs e) in e:\WebSite3\WebSite4\Default.aspx.cs:25
System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs e) +96
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +121
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +163
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +119
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +107
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +178
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3837
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.42
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "aaa")
{
int row = Convert.ToInt32(e.CommandArgument); //row 就是行号
//TextBox1.Text = GridView1.DataKeys[row].Value.ToString();
}
}
<asp:Button ID="Button1" runat="server" CommandArgument='<%# Bind("ID") %>' Text="Button" CommandName="Up" />
这样行吗`?
是根据数据循环就越多按妞。。不可能都CommandName 吧`
哈哈
我也遇到这样的问题
<asp:ButtonField ButtonType="Button" CommandName="DownLoad" Text="取得" >而你的是
<asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="aaa" Text="按钮" /> 分明你的是一个普通的按钮阿