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

RadGrid with ComboBox

2 Answers 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tommy Martin
Top achievements
Rank 1
Tommy Martin asked on 29 Jul 2008, 03:46 AM
I have a RadGrid control that has a RadComboBox control in edit mode in the Grid.  I am able to populate and select a default value on edit.  However, when I look for the updated values of the combobox, I am retrieving what was initially set as the value of the Rad ComboBox.  In the example code below, I am trying to store the value in the variable d from the SelectedValue of the cboAccess ComboBox

Thanks in adavance for your help.

Tommy

protected void rdgAccess_UpdateCommand(object source, GridCommandEventArgs e)

{

GridEditableItem item = (GridEditableItem)e.Item;

GridEditManager em = item.EditManager;

RadComboBox r = (RadComboBox)item.FindControl("cboAccess");

string d = r.SelectedValue.ToString();

string id = item.GetDataKeyValue("DerivedDepartment").ToString();

int vl = -1;

if (int.TryParse(r.SelectedValue, out vl) && vl > 0)

{

rdgAccess.Controls.Add(

new LiteralControl(id + " now has " + r.SelectedItem.Text + " access."));

}

else

{

rdgAccess.Controls.Add(

new LiteralControl(id + " does not have access."));

}

}

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Jul 2008, 06:16 AM
Hello Tommy,

Can you check if you have set the AutoPostBack property of the RadComboBox to true?

aspx:
 <telerik:RadComboBox ID="RadComboBox2" DataSourceID="SqlDataSource2" AutoPostBack="true" DataValueField="Text" DataTextField="Text" runat="server"
            </telerik:RadComboBox> 

Thanks
Princy.


0
Tommy Martin
Top achievements
Rank 1
answered on 29 Jul 2008, 01:19 PM
Princy,

No, I do not have the AutoPostBack set to true.  When I set that to true, it would change the drop down back to the initial value on the postback.  I load the drop down on the Edit_Command of the grid 

Here is what I have:

page.aspx (portion of rdgAccess)
        <telerik:GridTemplateColumn UniqueName="AccLevel" HeaderText="Access">  
            <ItemTemplate> 
                <asp:Label ID="lblAccess" runat="server"><%# Eval("AccessDesc") %></asp:Label> 
            </ItemTemplate> 
            <EditItemTemplate> 
                <telerik:RadComboBox ID="cboAccess" runat="server" Skin="Inox" Width="200px"></telerik:RadComboBox> 
                  
            </EditItemTemplate> 
        </telerik:GridTemplateColumn> 

page.aspx.cs (Edit_Command)
    protected void rdgAccess_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
 
 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
        {  
            GridEditableItem item = e.Item as GridEditableItem;  
            RadComboBox r = item.FindControl("cboAccess"as RadComboBox;  
 
            Database db = new Database(StoredProcedures.ConnectStrings.Dev);  
 
            DataSet ds = db.ExecuteDataSet(StoredProcedures.SPNames.WebSiteAccessLevels.SPName, CommandType.StoredProcedure);  
 
            r.DataSource = ds.Tables[0];  
            r.DataTextField = "AccessLevelDesc";  
            r.DataValueField = "AccessLevelID";  
            r.DataBind();  
 
            r.Items.Insert(0, new RadComboBoxItem("--------Select Access Level--------"));  
 
            Label lbl = e.Item.FindControl("lblAccessID"as Label;  
            r.SelectedValue = lbl.Text;  
 
 
 
        }  
        else if (e.Item is GridDataItem && !e.Item.IsInEditMode && Page.IsPostBack)  
        {  
            GridDataItem item = e.Item as GridDataItem;  
 
        }  
    } 


thanks again,

Tommy
Tags
Grid
Asked by
Tommy Martin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Tommy Martin
Top achievements
Rank 1
Share this question
or