Wednesday, April 27, 2022

ASP.NET grid view OnPreRender event

 <asp:GridView ID="grdBatchDetails" runat="server"  CssClass="table table-responsive" OnPreRender="grdBatchDetails_OnPreRender"

                    AutoGenerateColumns="False" EmptyDataText="No Records Found!" ShowHeaderWhenEmpty="True" 

                    AllowPaging="True" PagerSettings-PageButtonCount="10" PagerSettings-Mode="Numeric" OnDataBound="grdBatchDetails_DataBound"

                    onpageindexchanging="grdBatchDetails_PageIndexChanging"  PageSize="10" CellPadding="4" OnRowCommand="grdBatchDetails_RowCommand"

                    ForeColor="#333333" GridLines="None" Width="100%">


                <Columns>


                <asp:TemplateField HeaderText="S. No" ItemStyle-Width="10">

                <ItemTemplate>

                 <%#(grdBatchDetails.PageSize * grdBatchDetails.PageIndex) + (Container.DisplayIndex + 1)%>

                </ItemTemplate>

                <ItemStyle Width="10" />

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Batch ID" ItemStyle-Width="0" Visible="false">

                <ItemTemplate>

                  <asp:Label ID="Row_No" runat="server" Text='<%# Eval("Row_No") %>'/> 

                  <asp:Label ID="yearof" runat="server" Text='<%# Eval("yearof") %>'/> 

                  <asp:Label ID="Batch_id" runat="server" Text='<%# Eval("Batch_id") %>'/> 

                </ItemTemplate>

                <ItemStyle Width="0" />

                </asp:TemplateField>

<asp:GridView >


------------------------------------------------

protected void grdBatchDetails_OnPreRender(object sender, EventArgs e)

    {

        try

        {

            for (int i = 0; i < grdBatchDetails.Rows.Count; i++)

            {

                HyperLink btn_StudentRegister = grdBatchDetails.Rows[i].FindControl("btn_StudentRegister") as HyperLink;

                HyperLink btn_RED = grdBatchDetails.Rows[i].FindControl("btn_RED") as HyperLink;

                HyperLink btn_RED2 = grdBatchDetails.Rows[i].FindControl("btn_RED2") as HyperLink;

                HyperLink btn_RED3 = grdBatchDetails.Rows[i].FindControl("btn_RED3") as HyperLink;


                LinkButton Freeze_Status = grdBatchDetails.Rows[i].FindControl("Freeze_Status") as LinkButton;


                Label RegisterStudent_Status = grdBatchDetails.Rows[i].FindControl("RegisterStudent_Status") as Label;

                Label status = grdBatchDetails.Rows[i].FindControl("status") as Label;

                Label Row_No = grdBatchDetails.Rows[i].FindControl("Row_No") as Label;


                Label Original_Stu_count = grdBatchDetails.Rows[i].FindControl("Original_Stu_count") as Label;

                Label RED_StudentCount = grdBatchDetails.Rows[i].FindControl("RED_StudentCount") as Label;

                Label RED_EntryOn = grdBatchDetails.Rows[i].FindControl("RED_EntryOn") as Label;

                Label RED_StudentExamDate = grdBatchDetails.Rows[i].FindControl("RED_StudentExamDate") as Label;

                Label Exam_Result = grdBatchDetails.Rows[i].FindControl("Exam_Result") as Label;

                Label Exam_Status = grdBatchDetails.Rows[i].FindControl("Exam_Status") as Label;


                Label RED_BatchReqCount = grdBatchDetails.Rows[i].FindControl("RED_BatchReqCount") as Label;


                Label yearof = grdBatchDetails.Rows[i].FindControl("yearof") as Label;

                Label Batch_End_Date = grdBatchDetails.Rows[i].FindControl("Batch_End_Date") as Label;


                LinkButton batchCode = grdBatchDetails.Rows[i].FindControl("Batch_Code") as LinkButton;

}

}

}

No comments:

Post a Comment