网格视图数据绑定事件 [英] grid view databound event

查看:97
本文介绍了网格视图数据绑定事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用网格视图的数据绑定事件以及如何调用它,有人可以对此进行详细说明我将gridview绑定在按钮单击上,像这样

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) 
        //{ 


    //}

}

推荐答案

当Gridview的所有数据绑定完成时,将触发 DataBound 事件,这样您就可以对所有如您所知,那时Gridview中的所有行都将不再存在.您可以像调用其他任何事件一样调用它,在标记中设置属性,然后将代码放在代码后方:

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?

这篇关于网格视图数据绑定事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆