Gridview.row.count为零,为什么 [英] Gridview.row.count is zero why

查看:128
本文介绍了Gridview.row.count为零,为什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误消息

error message

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index







protected void ParamGV_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
        GridView gv = (GridView)(e.CommandSource);
        //string s = gv.DataKeys[row.RowIndex][0].ToString();
        int i = Convert.ToInt32(e.CommandArgument);
        GridViewRow Childrow = gv.Rows[i];
        //HeadNameDdl.SelectedValue = Server.HtmlDecode(Childrow.Cells[1].Text).Trim();
        //ViewState["ParameterId"] = Server.HtmlDecode(Childrow.Cells[2].Text).Trim();
        //ParameterNametxt.Text = Server.HtmlDecode(Childrow.Cells[3].Text).Trim();
    }



我有嵌套的网格视图,在内部网格中编辑即



i have nested grid view, in inner grid Edit i.e

<asp:CommandField SelectText="EDIT" ShowSelectButton="True" ItemStyle-Width="15"

                                                           HeaderText="EDIT">
                                                           <ItemStyle Width="15px" />
                                                       </asp:CommandField>





命令已提交

按下Edit时,会触发





command filed

On pressing Edit it firing

ParamGV_RowCommand


事件,但出现错误,我观察到gv.row.count为零,为什么


event but am getting above error , i observered gv.row.count is zero why

推荐答案

:thumbsdown:

我认为没有找到相同的记录.因此,记录数为零.

因此,您检查条件:玫瑰色:


:thumbsup:
:thumbsdown:

i think there is not found the equalent records. So, record count is Zero.

so, you check the condition:rose:


:thumbsup:


尝试以下代码....
try the following code....
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.Header && e.Row.RowType
!= DataControlRowType.Footer && e.Row.RowType !=
DataControlRowType.Pager)
{
LinkButton lblTagLink =new LinkButton();
lblTagLink = (LinkButton)e.Row.FindControl("btnAddTags");
lblTagLink.CommandArgument= e.Row.RowIndex.ToString();
}
}



然后在
中获取行索引



Then get the row index in

protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{

int RowIndex_ = int.Parse(e.CommandArgument.ToString());
Label lblMediaID_ =
(Label)GridView1.Rows[RowIndex_].FindControl("lblMedia_ID");

}


这篇关于Gridview.row.count为零,为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆