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

Editable grid - all rows, all columns

2 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kyle Parker
Top achievements
Rank 1
Kyle Parker asked on 12 Aug 2008, 04:19 PM
I've checked out some of the other posts and examples to accomplish this, but I'm not sure if I'm on the right track.

Here's what I'm trying to do:

Basic grid with 3 columns and multiple rows (here's the layout I'm trying to create, minus the RSS icon and "voice mail") - http://tmeister.iweb.bsu.edu/bsumessagecenter/

By default, the entire grid should be editable on load (except for the category name).  The user would then check the boxes for the category he/she would like to subscribe to.  On clicking the "update preferences" button, I would (on the server-side) process each box and insert that selection in the database.

How can I use a standard button (asp:Button) to loop through each row and access the items within that row to detemine whether or not the box is checked? 

I tried the <radG:GridClientSelectColumn ItemStyle-Width="40" /> but that didn't exactly meet my needs (couldn't have discrete selections per row).  I've also tried in the event handler for the button looping through each item:

foreach (GridItem Item in rgCategorySubscriptionList.MasterTableView.OwnerGrid.Items)

{

if (Item.Selected)
{
// test to see if the item is selected
Response.Write(
Convert.ToInt32(Item.OwnerTableView.DataKeyValues[Item.ItemIndex]["CategoryID"].ToString()));
}
}

But I'm not sure that I'm getting the info that I need with this...

Any suggestions would be greatly appreciated!

Thank you,
Kyle Parker

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Aug 2008, 10:02 AM
Hello Kyle,

I suppose you would be using CheckBoxes in TemplateColumns for the required scenario as only those CheckBoxes would be checkable in NormalMode. Check out the code below for the same.
aspx:
 <telerik:GridTemplateColumn HeaderText="Email" UniqueName="Email"
     <ItemTemplate> 
            <asp:CheckBox ID="CheckBox1"  runat="server" /> 
     </ItemTemplate> 
 </telerik:GridTemplateColumn> 
 <telerik:GridTemplateColumn HeaderText="TextMessage" UniqueName="TextMessage"
     <ItemTemplate> 
            <asp:CheckBox ID="CheckBox2"  runat="server" /> 
     </ItemTemplate> 
 </telerik:GridTemplateColumn> 

Also to loop through the checked CheckBoxes on a Button click you can try the following code.
cs:
  protected void Button2_Click(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.Items) 
        {            
            CheckBox chkbx = (CheckBox)item["Email"].FindControl("CheckBox1"); 
            if (chkbx.Checked == true) 
            { 
                string strg = chkbx.Checked.ToString(); 
            }         
        } 
    } 

Thanks
Princy.

0
Kyle Parker
Top achievements
Rank 1
answered on 13 Aug 2008, 12:11 PM
Princy,

Once again you helped me out with the controls - I appreciate it. 

I wanted to say that the Telerik controls have greatly improved the functionality, aesthetic, usability and perception of our applications.  They are great to use and helped us out a lot!

Thanks again,
Kyle
Tags
Grid
Asked by
Kyle Parker
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Kyle Parker
Top achievements
Rank 1
Share this question
or