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

Multiple GridDropDownColumns

5 Answers 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
SikhSuperman
Top achievements
Rank 1
SikhSuperman asked on 26 Sep 2012, 09:40 PM
Just starting to use telerik controls and I've combed through the forums and documentation for my problem but something hasn't clicked for me.  My scenario is that I have a radgrid with multiple griddropdowncolumns, 7 of them to be exact (days of the week).  The data is being bound in codebehind of type int for these 7 columns (there are other columns but those are coming back fine).  When I'm binding the data to the grid, the griddropdowncolumns do not populate at all.  The values should be between 1-5 to represent a status for each day.  So, initially, upon load of the radgrid, the columns will appear with respective status' and in edit mode the user shoul be able to select a different status for each day.  Sorry for the length, but trying to make my point here...
Here is a snippet of  my aspx code:
<telerik:GridDropDownColumn DataField="Mon" HeaderText="Mon" ListTextField=""
                                ListValueField="Mon" UniqueName="MonTitleColumn" DropDownControlType="RadComboBox" ColumnEditorID="MonTitleEditor1" />
                            <telerik:GridDropDownColumn DataField="Tue" HeaderText="Tue" ListTextField="StatusName"
                                ListValueField="Tue" UniqueName="TueTitleColumn" DropDownControlType="RadComboBox" ColumnEditorID="FebTitleEditor1" />
                            <telerik:GridDropDownColumn DataField="Wed" HeaderText="Wed" ListTextField="StatusName"
                                ListValueField="Wed" UniqueName="MarTitleColumn" DropDownControlType="DropDownList" ColumnEditorID="MarTitleEditor1" />
                            <telerik:GridDropDownColumn DataField="Thu" HeaderText="Thu" ListTextField="StatusName"
                                ListValueField="Thu" UniqueName="ThuTitleColumn" DropDownControlType="DropDownList" ColumnEditorID="AprTitleEditor1" />
                            <telerik:GridDropDownColumn DataField="Fri" HeaderText="Fri" ListTextField="StatusName"
                                ListValueField="Fri" UniqueName="MayTitleColumn" DropDownControlType="DropDownList" ColumnEditorID="MayTitleEditor1" />
How do I show the value in the db (1-5) for each of the GridDropDownColumns and in edit mode select the values 1-5...
I'm afraid I've spent all day and yesterday and my brain is fried.  And in the process I've thoroughly confused myself.
Any and all help is appreciated!
SS

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Sep 2012, 04:09 AM
Hi SikhSuperman,

Please bind the GridDropDownColumn by specifying the DataSourceID as follows, if you are binding RadGrid Declaratively.

ASPX:
<telerik:GridDropDownColumn DataField="EmployeeID" UniqueName="EmployeeID" ListTextField="EmployeeID" DropDownControlType="RadComboBox" ListValueField="EmployeeID" DataSourceID="SqlDataSource1" ></telerik:GridDropDownColumn>

If you are Binding the RadGrid in code behind, please populate the RadGrid as follows.

ASPX:
<telerik:GridDropDownColumn UniqueName="EmployeeID"  DropDownControlType="RadComboBox"></telerik:GridDropDownColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        DataRowView row = (DataRowView)e.Item.DataItem;
        item["EmployeeID"].Text = row["EmployeeID"].ToString(); //for showing the value in view mode
    }
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem item = (GridEditableItem)e.Item;  // in edit mode
        RadComboBox com = (RadComboBox)item["UniqueName"].Controls[0];
        com.DataSourceID = "DataSourceDataTable";
        com.DataTextField = "EmployeeID";
        com.DataValueField = "EmployeeID";
        com.DataBind();
    }
}

Thanks,
Shinu.
0
SikhSuperman
Top achievements
Rank 1
answered on 27 Sep 2012, 12:41 PM
Shinu,

Thanks for the quick reply and even more for a thorough reponse!  I'm thinking that i'm going to need to repeat the following piece of code for each of my 7 griddropdowncolumns (Since they're named different - mon-fri), right? 

Thanks again for your help!!
SS
item["EmployeeID"].Text = row["EmployeeID"].ToString(); // in view mode

GridEditableItem item = (GridEditableItem)e.Item; // in edit mode
RadComboBox com = (RadComboBox)item["drop"].Controls[0];
com.DataSourceID = "DataSourceDataTable";
com.DataTextField = "EmployeeID";
com.DataValueField = "EmployeeID";
com.DataBind();
0
Shinu
Top achievements
Rank 2
answered on 28 Sep 2012, 03:56 AM
Hi SikhSuperman,

You  have to repeat the code as shown below.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        DataRowView row = (DataRowView)e.Item.DataItem;
        item["TueTitleColumn"].Text = row["StatusName"].ToString();
        item["MarTitleColumn"].Text = row["StatusName"].ToString();
        . . .
        // repeat same for the rest
        . . .
 
    }
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem item = (GridEditableItem)e.Item;  // in edit mode
        RadComboBox com1 = (RadComboBox)item["TueTitleColumn"].Controls[0];
        com1.DataSourceID = "yourdatasource";
        com1.DataTextField = "StatusName";
        com1.DataValueField = "Tue";
        com1.DataBind();
 
        RadComboBox com2 = (RadComboBox)item["MarTitleColumn"].Controls[0];
        com2.DataSourceID = "yourdatasource";
        com2.DataTextField = "StatusName";
        com2.DataValueField = "Wed";
        com2.DataBind();
    . . .
        // repeat same for the rest
        . . .
    }
}

Thanks,
Shinu.
0
SikhSuperman
Top achievements
Rank 1
answered on 28 Sep 2012, 04:04 PM
Shinu -

Thank you for continuing to help.  I'm getting a "Specified argument was out of the range of valid values.
Parameter name: index" when I run the following code:
Dim radComboBox = DirectCast(item("JanTitleColumn").Controls(0), RadComboBox)

sorry -it's  in vb - but you get the idea.

This is happens when I try to go into edit mode - the grid refreshes and comes back the same as before without going into edit mode...

Any and all help is appreciated!
SS


0
SikhSuperman
Top achievements
Rank 1
answered on 30 Sep 2012, 03:00 AM
Shinu -

Thanks again for the help here.  I eventually figured this out...
For some reason I had to put in the logical 'Not' in the 'GridDataItem' check like so:
if (e.Item is GridDataItem && !e.Item.IsInEditMode)
 
//etc...

for whatever reason, this took away the nasty 'index' error and brough my editable grid back.

SS
Tags
Grid
Asked by
SikhSuperman
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
SikhSuperman
Top achievements
Rank 1
Share this question
or