Any ideas? I basically want to programatically reproduce the affect of clicking the edit button.
Thanks!
6 Answers, 1 is accepted
Set the EnablePostBackOnRowClick property to True and then try out the following code to set selected rows into EditMode.
aspx:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" AutoGenerateColumns="false" runat="server"> |
<MasterTableView > |
...... |
</MasterTableView> |
<ClientSettings EnablePostBackOnRowClick="True" > |
<Selecting AllowRowSelect="True" /> |
</ClientSettings> |
</telerik:RadGrid> |
cs:
protected void RadGrid1_PreRender(object sender, EventArgs e) |
{ |
foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items) |
{ |
if (dataItem.Selected) |
{ |
dataItem.Edit = true; |
} |
} |
RadGrid1.Rebind(); |
} |
Princy.
This is what I have, but it doesn't do anything except turn the rows yellow (indicating edit mode) but the edit controls (In Place Edit Mode) do not become available:
<asp:CheckBox ID="cbEditAll" runat="server" Text="Edit All" CssClass="Normal"
OnCheckedChanged="editAll" AutoPostBack="True" />
Public Sub editAll(ByVal sender As Object, ByVal e As System.EventArgs)
For Each gridItem As GridItem In rgT.MasterTableView.Items
gridItem.Edit =
True
Next
rgT.Rebind()
End Sub
Is it possible to do this? It seems like a simple thing to do but it doesn't seem to register that the rows are actually in open edit mode.
Thanks for the help!
You can try out the following code which allows you to set the entire grid into EditMode if the checkbox is checked and sets it to NormalMode if the checkbox is unchecked.
cs:
protected void CheckBox1_CheckedChanged(object sender, EventArgs e) |
{ |
foreach (GridDataItem data in RadGrid1.MasterTableView.Items) |
{ |
data.Edit = !data.Edit; |
} |
RadGrid1.Rebind(); |
} |
Thanks
Princy.
For Each data As GridDataItem In rgT.MasterTableView.Items
data.Edit =
True
rgT.Rebind()
Next
The problem is it still only sets the rows to be yellow as though they were in edit mode but they are still not editable. I don't see the editable controls still. There must be command that tells it to open up the editable controls in my templated columns.
If (e.CommandName = "EditAll") Then
For Each item As GridItem In rgT.MasterTableView.Items
Dim cbAppCntrl As CheckBox = CType(item.FindControl("chkApproved"), CheckBox)
If (TypeOf item Is GridDataItem) Then
If (Not cbAppCntrl.Checked) Then
item.Edit =
True
ElseIf (cbAppCntrl.Checked) Then
item.Edit =
False
End If
End If
Next
GetTransactions()
End If
The problem is that as you can see I am trying to NOT put the rows that are checked as approved (cbAppCntrl.Checked) into edit mode, yet it seems to ignore this. It hits the code and sets the edit property to false as it should, yet after I requery and refill the grid those approved rows are still in edit mode.
Any ideas?
Thanks for the help Princy you led me in the right direction I just wasn't able to get it to work with a checkbox (which is fine) and I can't seem to skip the approved rows being set to edit mode.
protected void m_rgPolicyModules_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
DataRowView drv = e.Item.DataItem as DataRowView;
GridEditableItem item = e.Item as GridEditableItem;
if (drv["ModuleType"].ToString() != "Optional Module")
item[
"Selected"].Enabled = false;
}
}
Hope this helps someone :)