的RowDataBound我有一個2個GridView的。第一個網格有一個按鈕,當點擊它時,它會根據點擊的按鈕的ID填充第二個網格。從另一個調用函數
然後我必須在的RowDataBound功能代碼基礎上選擇該行,顯示網格。但問題是代碼在填充函數之前自動運行RowDataBound。所以第二個網格不顯示。
代碼的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>
後面的代碼:
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";
}
}
}
}
代碼選擇按鈕:
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();");
}
所以,問題是,當我點擊的選擇按鈕電網運行的RowDataBound
第一則gridviewParent_SelectedIndexChanged
但我需要運行012首先是。我可以從gridviewParent_SelectedIndexChanged
撥打RowDataBound
功能嗎?
的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();
}
}
}
能否請您發表您的Page_Load方法以及包含跌倒數據綁定所有其他方法()? – Markus
@Markus將Page_Load代碼添加到我的問題中。這是DataBind被調用的唯一地方。當我點擊select時,它會進入方法 – user123456789
的'else'部分,謝謝;我想我已經確定了這個問題。請看我最新的答案。 – Markus