Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 21, 2007 01:19 AM by Rex Lin - MSFT
Jun 19, 2007 07:07 PM|LINK
I have gridview and dynamic checkboxes in there, when user clicks one of the checkboxes, gridview's that row goes to edit mode and also filters data inside the dropdownlist and populates dropdownlist. I have created oncheckchanged() event handler that if
fires when someone clicks the checkbox, but when it is more than one checkbox clicks , after postback doesn't remember the previous values of the other checkbox. What I need to do? I am including commented ones so you can see what I even tried, didn't work.
txtmessage.Text = GridView1.DataKeys(currentrow).Value.ToString()
GridView1.EditIndex = currentrow
GridView1.EditIndex = -1
'even tried to gridview1.databind() instead calling bindgrid()
View state Problem
Jun 19, 2007 08:54 PM|LINK
I see that you do data binding manually. However, do you bind your controls to data source?
If so, it means that you bind data bind GridView twice and you lose values because of this.
If you prefer manual data binding remove DataSourceID property and set DataSource property immediately before calling DataBind. Moreover, be sure that you don't call DataBind twice.
You may disable ViewState for gridview if you rebind cotntrol on every postback, unless you need it for some other reason.
Jun 19, 2007 09:07 PM|LINK
thank you for replying, can you be more specific where and what shoudl I do?
Jun 19, 2007 09:15 PM|LINK
Jun 19, 2007 09:31 PM|LINK
I have checked that I don't have datasourceid in the aspx page, I called that in bindgrid()
Ihave take bindgrid out inside the checkchanged event and now, it can remmeber checkbox value, but doesn't go to edit mode, and when I check diffrent checkbox it gives me error , failed to load viewstate.
Jun 19, 2007 10:00 PM|LINK
In you original code that you posted to this forum you were calling BindGrid after you set EditIndex. If you still do it, it may be a reason why GridView does not switch to editing mode.
Regarding the error with loading view state, can you describe the whole sequence starting from fresh loaded page.
Jun 19, 2007 10:14 PM|LINK
I have take it bindgrid() out on checkchanged event. So, I don't have to call twice, because I am calling at page load.
But, that time, edit mode is not showing in my gridview when I click checkbox and postbacks, even though on checkchanged event I have
GridView1.EditIndex = currentrow , still doesn't show edit mode, it only shows my checkbox I have checked.
BUT, when I left Bindgrid() on the checkchanged() event that time I was getting my editmode along with whatever checkbox I have checked, but only thing was It was not remember previous checkbox values. For ex. If I have checked first checkbox,
postbacks and shows me edit mode of the first checkbox, then I go ahead and check second checkbox, it only remembers and shows me second checkbox, not first one, I want to see both.
So, feels like I don't need bindgrid on checkchanged event but when I take it out that I don't even see edit mode for fist checkbox.
Jun 19, 2007 10:24 PM|LINK
Well, you are right that you need data binding to make GridView create edit row for the EditIndex . However, if you do data binding twice, the second time checkboxes wil lnot process post data and you lose their state. How do you use your checkboxes?
Can you restore their checked state from data source? If so, you can data bind their checked property. If you cannot do this, I would walk all checkboxes before calling second DataBind and restore their state on second databinding. Do you think it is feasible?
Jun 19, 2007 10:55 PM|LINK
I just checked on the very simple sample with DataSourceID bound GridView and enabeld viewstate. unfortunatelly, GridView loses both checkboxes value and viewstate of any controls in templated columns if you switch gridview to edit mode.
I cannot find aney easy workaround, so I think the best is to find a way to set the correct checked state on second databinding. (perhaps as I suggested earlier to save and restore their state)
Jun 20, 2007 12:13 AM|LINK
Are you serious, Oh my God, I have been tried to do that past couple of days. What is your second suggestion, how can I do that?