Click here to Skip to main content
15,898,020 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

DataGridDemo[^] See the section "Checkboxes and TextBoxes"
 
Share this answer
 
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
C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)//not for postbacks
            {
                GV.DataSource = CreateDataSource();
                GV.DataBind();
            }
        }


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

//feel free to give FeedBack
 
Share this answer
 
v2
Comments
RaviRanjanKr 9-Nov-11 16:12pm    
[Edited]Code is wrapped in "pre" tag[/Edited]
A suggestion :- Always wrap your code in Pre tag to give bettter readability to user.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900