GridView 中的值问题

来源:百度知道 编辑:UC知道 时间:2024/05/18 10:25:54
void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName=="All")
{
int i=Convert.ToInt32(e.CommandArgument);
GridViewRow row=GridView1.Rows[i];
string s=row.Cells[1].Text;
Label1.Text=s;
}
}

问题 上面得方法只可以用在 LinkBution 按钮中吗? 其他的不可以吗 比如<asp:ImageButtion ID="ImageButtion1" runat="server" CommandName="Add"> 如果可以怎么排除e.CommandArgument的格式错误
除LinkButtion按钮 其他的 e.CommandArrgument 返回的都是空 "" 得不到行的信息

实现这个功能的有控件:LinkBution,ImageButtion,Buttion。
e.CommandArgument的格式错误就是类型不对,你把e.CommandArgument获取的数据转换成int,如果传的参数不是int型的就会出现格式不正确。可以先用string接收,再看是什么类型,具体转换下就可以了

<asp:ImageButtion ID="ImageButtion1" runat="server" CommandName="Add" CommandArrgument="赋值"> 应该是你没有给这个属性赋值。

普通的<asp:Button 也是可以的基本上用法一样,在这里哥们就不赘述了。

参考:
for (int i = 0; i < dgField.Items.Count; i++)
{
tb = (TextBox)this.dgField.Items[i].Cells[2].FindControl("txtProperty");
ddl = (DropDownList)this.dgField.Items[i].Cells[2].FindControl("ddlProperty");

}

ImageButton控件没有commandargument这个属性怎么能排除那个错误呢。