
kollam2003
Top achievements
Rank 1
kollam2003
asked on 27 Jan 2009, 10:18 AM
I want to save all the values from a grid.
I have 100 records in a grid.
The page count is 10.
Each row has radio buttons in it.
I want to save all the changes in one button click.
How to achieve it.
I have 100 records in a grid.
The page count is 10.
Each row has radio buttons in it.
I want to save all the changes in one button click.
How to achieve it.
6 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 27 Jan 2009, 11:00 AM
Hello,
A suggestion would be to set AllowPaging to false and then update the records on the button click event as shown below:
cs:
Thanks
Princy.
A suggestion would be to set AllowPaging to false and then update the records on the button click event as shown below:
cs:
protected void Save_Click(object sender, EventArgs e) |
{ |
RadGrid1.MasterTableView.AllowPaging = false; |
RadGrid1.Rebind(); |
foreach (GridDataItem item in RadGrid1.Items) |
{ |
string strtxt = item.GetDataKeyValue("DataKeyName").ToString(); |
} |
//update query |
RadGrid1.MasterTableView.AllowPaging = true; // set paging back to true after updating |
RadGrid1.Rebind(); |
} |
Thanks
Princy.
0

kollam2003
Top achievements
Rank 1
answered on 27 Jan 2009, 11:21 AM
But if I rebind it i will loss the state.
Each row is having radio buttons.
The radio buttons selection is made & then only i have to save.
Each row is having radio buttons.
The radio buttons selection is made & then only i have to save.
0

Shinu
Top achievements
Rank 2
answered on 27 Jan 2009, 11:57 AM
Hi kollam2003,
Here is a help article which explains how to persist the state of CheckBox in a GridTemplateColumn on Rebind. You can apply the same logic with RadioButton also.
Persisting CheckBox control state in GridTemplateColumn on rebind
Thanks
Shinu.
Here is a help article which explains how to persist the state of CheckBox in a GridTemplateColumn on Rebind. You can apply the same logic with RadioButton also.
Persisting CheckBox control state in GridTemplateColumn on rebind
Thanks
Shinu.
0

kollam2003
Top achievements
Rank 1
answered on 28 Jan 2009, 05:52 AM
Hai Shinu,
It didnt help me.
Can you plz upload a working example.
It didnt help me.
Can you plz upload a working example.
0

kollam2003
Top achievements
Rank 1
answered on 29 Jan 2009, 08:28 AM
any one solved the problem?
0

kollam2003
Top achievements
Rank 1
answered on 29 Jan 2009, 08:55 AM
To maintain the state I have done it by using the following code.
But I have a doubt if i have more controls in the grid, should I use seperate Viewstates for each control?. Is it the right way?
But I have a doubt if i have more controls in the grid, should I use seperate Viewstates for each control?. Is it the right way?
private void RememberOldValues() |
{ |
ArrayList _rbPresent = new ArrayList(); |
int index = -1; |
foreach (GridDataItem _GridDataItem in radGVStudents.Items) |
{ |
index = Convert.ToInt32(_GridDataItem.OwnerTableView.DataKeyValues[_GridDataItem.ItemIndex]["StudentID"].ToString()); |
bool _rbPresentChecked = ((RadioButton)(_GridDataItem.FindControl("rbPresent"))).Checked; |
// Check in the ViewState |
if (ViewState[CHECKED_rbPresent] != null) |
_rbPresent = (ArrayList)ViewState[CHECKED_rbPresent]; |
if (_rbPresentChecked) |
{ |
if (!_rbPresent.Contains(index)) |
_rbPresent.Add(index); |
} |
else |
_rbPresent.Remove(index); |
} |
if (_rbPresent != null && _rbPresent.Count > 0) |
ViewState[CHECKED_rbPresent] = _rbPresent; |
} |
private void RePopulateValues() |
{ |
ArrayList _rbPresent = (ArrayList)ViewState[CHECKED_rbPresent]; |
if (_rbPresent != null && _rbPresent.Count > 0) |
{ |
foreach (GridDataItem _GridDataItem in radGVStudents.Items) |
{ |
int index = Convert.ToInt32(_GridDataItem.OwnerTableView.DataKeyValues[_GridDataItem.ItemIndex]["StudentID"].ToString()); |
if (_rbPresent.Contains(index)) |
{ |
((RadioButton)(_GridDataItem.FindControl("rbPresent"))).Checked = true; |
} |
} |
} |
} |
protected void radGVStudents_PageIndexChanged(object source, GridPageChangedEventArgs e) |
{ |
// Put old values in a ViewState |
RememberOldValues(); |
radGVStudents.CurrentPageIndex = e.NewPageIndex; |
radGVStudents.Rebind(); |
RePopulateValues(); |
} |
protected void radGVStudents_PreRender(object sender, EventArgs e) |
{ |
if (ViewState[CHECKED_rbPresent] != null) |
{ |
RePopulateValues(); |
} |
} |