Ho 2 visualizzazioni Grid. La prima griglia ha un pulsante che quando viene cliccato popolerà una seconda griglia con i dati basati sull'id del pulsante cliccato.chiama RowDataBound da un'altra funzione
Quindi ho il codice nella funzione RowDataBound per mostrare la griglia in base alla riga selezionata. Ma il problema è che il codice esegue automaticamente RowDataBound prima della funzione populate. Quindi la seconda griglia non viene visualizzata.
Codice in materia di 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>
codice dietro:
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";
}
}
}
}
Codice per pulsante di selezione:
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();");
}
Quindi il problema è quando clicco sul pulsante Seleziona nella griglia corre il RowDataBound
prima poi il gridviewParent_SelectedIndexChanged
ma ho bisogno di eseguire 012 Prima il. Posso chiamare la funzione RowDataBound
da gridviewParent_SelectedIndexChanged
?
funzione Page_Load:
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();
}
}
}
Potete per favore pubblicare il tuo metodo Page_Load e tutti gli altri metodi che contengono una caduta a DataBind()? – Markus
@Markus aggiungi il codice Page_Load alla mia domanda. Questo è l'unico posto chiamato DataBind. Quando clicco su seleziona, entra nella parte 'else' del metodo – user123456789
grazie; Penso di aver identificato il problema; per favore vedi la mia risposta aggiornata – Markus