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

Programatically put all grid rows in edit mode

5 Answers 300 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Acadia
Top achievements
Rank 1
Iron
Acadia asked on 05 Nov 2008, 01:01 PM

I am struggling to understand why the following code is putting all rows into edit mode when I click my "Edit All" button, when it should be putting all rows except those which have their checkbox checked.  When the code hits the if statement for the checked rows it recognizes that the checkbox is checked and falls into the else part to set item.Edit = False, but after retrieving the transactions in the GetTransactions() method the rows are ALL in edit mode.

I just don't understand how that is happening.  Dooes anyone have any ideas?

Here is the 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 (Not cbAppCntrl.Checked) Then
item.Edit = True
ElseIf (cbAppCntrl.Checked = True) Then
item.Edit = False
End If
Next

 

GetTransactions()

End If

Thanks!!!

5 Answers, 1 is accepted

Sort by
0
Andrei
Top achievements
Rank 1
answered on 05 Nov 2008, 10:27 PM
Hello there,

I can't tell you why do you get that behavior because I'm new to ASP.NET and Telerik Rad AJAX constrols.

Instead I need a grid that puts all rows in edit mode.

I've tried your code but I recieved some unexpected behavior so can you give me some more details where did you insert that code and what was the trigger for that behavior?

Thanx a lot,

Andrei
0
Princy
Top achievements
Rank 2
answered on 06 Nov 2008, 04:45 AM
Hello Andrei,

You can try out the following code to put the entire grid in EditMode.
cs:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
       foreach (GridDataItem item in RadGrid1.Items) 
        { 
            item.Edit = true;  
        } 
        RadGrid1.Rebind(); 
    } 

Thanks
Princy.
0
Andrei
Top achievements
Rank 1
answered on 06 Nov 2008, 12:43 PM
Well it's not working for me, the only row that gets into "edit mode" is the last one, no matter if the grid is pagged or not.

Is the Items collection of RadGrid refers only to the items within current row?

Here is the code:

ASPX File:

<telerik:RadGrid
                ID="ProductsDataSheet"
                runat="server"
                AutoGenerateColumns="false"
                DataSourceID="ProductsDS"
                AllowPaging="true"
                PageSize="15"
                AllowFilteringByColumn="true"
               
                ShowStatusBar="true"
                Skin="Office2007"
                OnPreRender="ProductsDataSheet_PreRender">
               
                <MasterTableView DataSourceID="ProductsDS">
                    <Columns>
                        <telerik:GridBoundColumn
                            HeaderText="Product"
                            DataField="ProductName"
                            UniqueName="ProductName"
                            DataType="System.String" />
                           
                        <telerik:GridDropDownColumn
                            HeaderText="Category"
                            DataSourceID="ProductsDS"
                            DataField="CategoryID"
                            ListTextField="CategoryName"
                            ListValueField="CategoryID" />
                           
                        <telerik:GridDropDownColumn
                            HeaderText="Supplier"
                            DataSourceID="ProductsDS"
                            DataField="SupplierID"
                            ListTextField="SupplierName"
                            ListValueField="SupplierID" />                       
                    </Columns>

                </MasterTableView>
            </telerik:RadGrid>

Code Behind File:
    protected void ProductsDataSheet_PreRender(object sender, EventArgs eventArgs) {
        foreach (GridDataItem item in this.ProductsDataSheet.Items) {
            item.Edit = true;
        }
        this.ProductsDataSheet.Rebind();
    }
0
Shinu
Top achievements
Rank 2
answered on 06 Nov 2008, 01:02 PM
Hello Andrei,

Try setting the AllowMultiRowEdit property for the grid to True as shown below.
Aspx:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource2" AllowMultiRowEdit="True" runat="server" OnPreRender="RadGrid1_PreRender">  
  <MasterTableView DataSourceID="SqlDataSource2" > 

Thanks
Shinu.
0
Andrei
Top achievements
Rank 1
answered on 06 Nov 2008, 01:04 PM
It works perfect!

Thank you
Tags
Grid
Asked by
Acadia
Top achievements
Rank 1
Iron
Answers by
Andrei
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Share this question
or