开发者

Alternative to overriding Render for adding ClientScript.GetPostBackEventReference attribute in nested GridViews

Is there an alternative to overriding the page render method to make my gridview rows clickable. This works fine in single grid view mode, but when nested , although the code steps through and seems ok, I don't get the selected index firing on the nested grid view.

Edit: I have tried the following line in RowDataBound, but don't know why I don't get the selected index firing

e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(e.Row.Parent.Parent, "Select$" + e.Row.RowIndex);

protected override void Render(HtmlTextWriter writer)
{
    if (gdvServiceSchedule.Rows.Count > 0)
    {
        foreach (GridViewRow row in gdvServiceSchedule.Rows)
        {
            开发者_如何转开发if (row.RowType == DataControlRowType.DataRow)
            {

                    row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(this.gdvServiceSchedule, "Select$" + row.DataItemIndex, true)); 
            }
            if (row.RowState == DataControlRowState.Edit || row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate))
            {
                GridView gv = (GridView)row.FindControl("gdvServiceScheduleVariants");
                if(gv.Rows.Count > 0)
                {
                    foreach(GridViewRow row2 in gv.Rows)
                    {
                        if(row2.RowType ==DataControlRowType.DataRow)

                        {
                            row2.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(row.FindControl("gdvServiceScheduleVariants"), "Select$" + row2.DataItemIndex, true)); 
                        }
                    }
                }

            }
        }
    }
    base.Render(writer);
}


use the MVC framework... but seriously, can you just create another of your custom control inside of the row instead of a GridView?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜