在GridView中动态创建的复选框 [英] dynamically created checkboxes in gridview

查看:86
本文介绍了在GridView中动态创建的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

am在我的asp.net应用程序中使用网格视图控件.在该网格视图中,我具有
使用模板field动态创建了复选框.我的问题是每当单击
任何按钮(在回发期间)gridview中的复选框列为空,我如何保持状态
的复选框?
在此先感谢

am using a grid view control in my asp.net application.in that gridview i have
created checkboxes dynamically using template field.my problem is whenever am clicking
any button(during a postback) the checkbox column in the gridview is empty how can i maintain the state
of the checkboxes?
thanks in advance

推荐答案

DataGridDemo [ ^ ]请参见复选框和文本框"部分
DataGridDemo[^] See the section "Checkboxes and TextBoxes"


即使您通过<ItemTemplate>
添加控件 它将自动维护ViewState属性,
但对于您而言,这是将数据绑定到您的问题GrideView,
检查要绑定数据的位置.在回发中,您不应再次绑定数据(因为它类似于完成页面刷新)
如果您使用Page_load()绑定数据,则必须为回发设置条件..
如图所示
Even youre adding the controls through <ItemTemplate>
it will automatically maintains the ViewState property,
but in your case it is the matter of Binding data to youe GrideView,
Check where you are binding the data.. In postback you shouldn''t bind the data again (as it is similar to complete page refresh)
hense if you use Page_load() to bind the data, then you have to make condition for postback..
As shown
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)//not for postbacks
            {
                GV.DataSource = CreateDataSource();
                GV.DataBind();
            }
        }



因此,对于回发,数据将来自LoadPostBack()

//随意提供反馈



So for post backs the data will get from LoadPostBack()

//feel free to give FeedBack


这篇关于在GridView中动态创建的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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