I have 2 Gridviews. The first grid has a button that, when pressed, will fill the second grid with data based on the identifier of the button pressed.
Then I have the code in the RowDataBound function to show the grid based on the selected row. But the problem is that the code starts RowDataBound automatically before the fill function. Thus, the second grid is not displayed.
Code for GridView:
<asp:GridView style="width:75%" ID="gvCVRT" ShowHeaderWhenEmpty="true" CssClass="tblResults" runat="server" OnRowDataBound="gvCVRT_RowDataBound" OnSelectedIndexChanged="gridviewParent_SelectedIndexChanged" DataKeyField="ID" DataKeyNames="ChecklistID" AutoGenerateColumns="false" allowpaging="false" AlternatingRowStyle-BackColor="#EEEEEE"> <HeaderStyle CssClass="tblResultsHeader" /> <Columns> <asp:BoundField DataField="ChecklistID" HeaderText="ID" ></asp:BoundField> <asp:CommandField ShowSelectButton="True" HeaderText="Select" /> <asp:BoundField DataField="ChecklistDate" HeaderText="Checklist Date" dataformatstring="{0:dd/MM/yyyy}"></asp:BoundField> <asp:BoundField DataField="User" HeaderText="User" ></asp:BoundField> <asp:BoundField DataField="Note" HeaderText="Note" ></asp:BoundField> </Columns> </asp:GridView>
Code behind:
protected void gvCVRT_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { lookupCVRT work = (lookupCVRT)e.Row.DataItem; GridView gv = sender as GridView; if (work.ID != null) { int index = gv.Columns.HeaderIndex("Select"); if (index > -1) { e.Row.Cells[index].Attributes.Add("class", "gvCVRTRow"); e.Row.Cells[index].ToolTip = "Click here to Edit Checklist"; } } } }
Code for selection button:
protected void gridviewParent_SelectedIndexChanged(object sender, EventArgs e) { List<lookupCVRT> workDetails = lookupCVRT.GetChecklistItemsByChecklistID(Company.Current.CompanyID, ParentID.ToString(), gvCVRT.SelectedDataKey.Value.ToString()); gvCVRTDetails.DataSource = workDetails; gvCVRTDetails.DataBind(); FireJavascriptCallback("setArgAndPostBack ();"); }
So the problem is that when I click the Select button in the grid, it starts RowDataBound first and then gridviewParent_SelectedIndexChanged , but I need to start gridviewParent_SelectedIndexChanged first. Can I call the RowDataBound function from gridviewParent_SelectedIndexChanged ?
Page_Load function:
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { GetChecklistID = ""; if (ParentID.HasValue) { ViewState["ParentID"] = ParentID; List<lookupCVRT> work = lookupCVRT.GetCVRTItems(Company.Current.CompanyID, ParentID.ToString()); ViewState["CVRT"] = work; gvCVRT.DataSource = work; gvCVRT.DataBind(); } } else { if (ViewState["ParentID"] != null) { ParentID = (int?)ViewState["ParentID"]; List<lookupCVRT> work = ViewState["CVRT"] as List<lookupCVRT>; gvCVRT.DataSource = work; gvCVRT.DataBind(); } } }
user123456789
source share