Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grid view databound event

Tags:

asp.net

how data bound event of grid view is used and how is it called could somebody elaborate a bit on this please i bind gridview on button click like this

DataTable dt = placedStudentManager.GetPlacedStudentList(sb, passoutYear, courseList);
                if (dt != null && dt.Rows.Count != 0)
                {
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                    GridView1.Visible = true;
                    Btnsave.Visible = true;
                    ViewState["dt"] = dt;
                }

and whenever i need it again to bind i use view state like this, but can data bound event be any use instead of having view state can i use directly data bound event or some good alternate exist please let me know

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {

        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = (DataTable)ViewState["dt"];
        GridView1.DataBind();
        GridView1.Visible = true;
        Btnsave.Visible = true;
       // StringBuilder str=(StringBuilder)ViewState["chk"];
        //foreach (GridViewRow row in GridView1.Rows) 
        //{ 


    //}

}
like image 946
NoviceToDotNet Avatar asked Sep 05 '25 16:09

NoviceToDotNet


1 Answers

The DataBound event fires when all the databinding for the Gridview is finished, so that you could do, say, subtotals of all the rows in the Gridview at that point as you know there aren't going to be any more rows in the view. You call it like any other event, set the attribute in your markup and put the code in your code-behind:

<asp:gridview id="Gridview1" runat="server" ondatabound="Gridview1_DataBound" 
...
</asp:gridview>

private void Gridview1_DataBound(EventArgs e)
{
    ...
}

Could you use it in what you're doing? Possibly - can you put a bit more detail in your question about the way you're thinking?

like image 135
PhilPursglove Avatar answered Sep 08 '25 11:09

PhilPursglove