This is a migrated thread and some comments may be shown as answers.

How to loop through a rad grid ad set certain rows into edit mode

6 Answers 428 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Acadia
Top achievements
Rank 1
Iron
Acadia asked on 18 Sep 2008, 11:01 AM
I thought this was done with gridItem.Edit = true and I have used ths successfully in other scenarios, but I tried iterating through my grid with a for/next and all this seems to do is turn the rows yellow.  It does not show the edit mode controls.

Any ideas?  I basically want to programatically reproduce the affect of clicking the edit button.

Thanks!

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Sep 2008, 11:46 AM
Hello Acadia,

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.
0
Acadia
Top achievements
Rank 1
Iron
answered on 18 Sep 2008, 12:19 PM
I'm sorry Princy, I should have explained my scenario better.  I want to force all rows in a grid to edit mode simultaneously by clicking a "Edit All" checkbox outside of the grid.

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!

0
Princy
Top achievements
Rank 2
answered on 19 Sep 2008, 03:15 AM
Hello Acadia,

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.
0
Acadia
Top achievements
Rank 1
Iron
answered on 19 Sep 2008, 12:15 PM
I use VB.net so I tried this modification of your code:

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.

0
Acadia
Top achievements
Rank 1
Iron
answered on 19 Sep 2008, 01:46 PM
By changing the checkbox to a button and making it a command item I was able to set all rows in the grid to edit mode using the following code:

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.

0
Mark
Top achievements
Rank 1
answered on 04 Dec 2008, 07:38 PM
I don't know if this is still an issue for you, but I had the same problem.  I solved it by doing my checking in ItemDataBound:

 

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 :)

Tags
Grid
Asked by
Acadia
Top achievements
Rank 1
Iron
Answers by
Princy
Top achievements
Rank 2
Acadia
Top achievements
Rank 1
Iron
Mark
Top achievements
Rank 1
Share this question
or