开发者

c# GridView RowDataBound Error

开发者 https://www.devze.com 2023-03-17 15:43 出处:网络
I have a开发者_StackOverflow中文版 gridview that should be editable when a row is clicked. This gridview is clickable in a row so when I clicked it, the row will be displayed in other pages for editin

I have a开发者_StackOverflow中文版 gridview that should be editable when a row is clicked. This gridview is clickable in a row so when I clicked it, the row will be displayed in other pages for editing reason. I got an error like this

Specified argument was out of the range of valid values. Parameter name: index.

This is happening for this line:

LinkButton _singleClickButton = (LinkButton)e.Row.Cells[1].Controls[1];

How can I fix this?

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // Get reference to button field in the gridview.  
            LinkButton _singleClickButton = (LinkButton)e.Row.Cells[1].Controls[1];
            string _jsSingle = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "Select$" + e.Row.RowIndex);
            e.Row.Style["cursor"] = "hand";
            e.Row.Attributes["onclick"] = _jsSingle;
        }
    }  
}


You should be using something like e.Row.FindControl("linkbuttonid"). This will get you the required link button from the current row, then you can attach your handlers to the same and perform your logic

0

精彩评论

暂无评论...
验证码 换一张
取 消