後得到回傳我有有兩個事件 - 1.RowDataBound 2.SelectedIndexChanged RowDataBound事件成功觸發,但在此之後的SelectedIndexChanged事件也不網頁獲得的回發一個gridview。我需要進行頁面刷新。 以下是GridView的結構。的GridView的SelectedIndexChanged不點火,也不頁面RowDataBound事件
<asp:GridView ID="grdHead" runat="server" AutoGenerateColumns="false" Width="100%"
CssClass="mGrid" DataKeyNames="EmpId,ReqType,S,ReturnComplete,BookletNo" OnRowDataBound="grdHead_RowDataBound"
OnSelectedIndexChanged="grdHead_SelectedIndexChanged">
<Columns>
<asp:TemplateField HeaderText="Sr No.">
<ItemTemplate>
<asp:Label ID="lblSrNo" runat="server" Text='<%# Container.DataItemIndex + 1 %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RequisitionNo" HeaderText="Requisition No." ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="BookletNo" HeaderText="Booklet No." ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="EmpFullName" HeaderText="Employee Name" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="SiteName" HeaderText="Site Name/Branch Name" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="RMName" HeaderText="Requested By" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="CreatedDate" HeaderText="Requested Date" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Status" HeaderText="Status" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="SingleDate" HeaderText="Status Date" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
</asp:GridView>
我用以下語句RowDataBound事件:
protected void grdHead_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(grdHead, "Select$" + e.Row.RowIndex);
e.Row.Attributes["style"] = "cursor:pointer";
}
}
catch (Exception)
{
throw;
}
}
所以請幫助我走出這個問題。 在此先感謝。
下面是SelectedIndexChanged事件代碼:
protected void grdHead_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
SetParameters();
for (int i = 0; i < grdHead.Rows.Count; i++)
{
grdHead.Rows[i].BackColor = System.Drawing.Color.White;
}
int Index = grdHead.SelectedRow.RowIndex;
grdHead.Rows[Index].BackColor = System.Drawing.Color.SkyBlue;
ViewState["RequisitionId"] = Convert.ToString(grdHead.Rows[Index].Cells[1].Text.Trim());
ViewState["EmpId"] = Convert.ToString(grdHead.DataKeys[Index]["EmpId"]);
DataTable Dt = ReqBll.BindMatDetails(CompanyID, ViewState["RequisitionId"].ToString());
if (Dt.Rows.Count > 0)
{
grdDetails.DataSource = Dt;
grdDetails.DataBind();
}
else
{
grdDetails.DataSource = null;
grdDetails.DataBind();
}
btnExport.Enabled = true;
}
catch (Exception)
{
throw;
}
}
你能顯示grdHead_SelectedIndexChanged的代碼? – sr28 2015-03-19 10:21:04
該頁面沒有獲得PostBack.It甚至不會去PageLoad事件。 – 2015-03-19 10:24:33
嘗試將RowDataBound事件中的邏輯添加到RowCreated事件中。它看起來像你試圖爲整行創建一個點擊事件,而不是使用標準的提交按鈕。我認爲需要添加到RowCreated事件中。 – sr28 2015-03-19 10:51:23