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

How to get comboBox id in grid itembound event?

3 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Guruvu
Top achievements
Rank 1
Guruvu asked on 25 Nov 2010, 11:19 AM
Hi,

Here is my code:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridEditFormItem && e.Item.IsInEditMode)// if EditMode is EditForm or PopUp
       {
           GridEditFormItem editItem = (GridEditFormItem)e.Item;
           RadComboBox ddlCity = editItem.FindControl("gvddlPOWCity") as RadComboBox;
           string city = ddlCity.SelectedValue;
           . . . . . . . .
       }
   }


Here,I am getting e.Item.IsInEditMode is always false.I am set the property in MasterTable view as below:

<MasterTableView DataKeyNames="POWId" EditMode="EditForms">

Is there any more modifications need to perform.Please tell me...

Thanks...

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Nov 2010, 11:42 AM
Hello,


I am not sure about where you placed the RadComboBox, is it inside ItemTemplate or EditItemTemplate?

The code that you tried will work when item in EditMode only and not for the items in normal mode. In the case of you need to access RadComboBox placed in ItemTemplate, then you should use the following code without checking for e.Item.IsInEditMode.

Code:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem) e.Item;
        RadComboBox combo = (RadComboBox)item.FindControl("RadComboBox1");
    }
}

And the aspx is as shown below:
<telerik:GridTemplateColumn UniqueName="CustomerID1" HeaderText="ID">
          <ItemTemplate>
                  <telerik:RadComboBox ID="RadComboBox1" runat="server">
                  </telerik:RadComboBox>
          </ItemTemplate>
</telerik:GridTemplateColumn>



-Shinu.
0
Guruvu
Top achievements
Rank 1
answered on 25 Nov 2010, 12:02 PM
Hi Shinu,

Here i am placed Combobox in EditItem Template.I am getting the error while editing the record...

Please suggest me...

Thanks.
0
Vasil
Telerik team
answered on 25 Nov 2010, 04:34 PM
Hello guruvu,

Try the following approach.

.aspx:
<telerik:GridTemplateColumn UniqueName="MyTemplateColumn">
    <EditItemTemplate>
        <telerik:RadComboBox runat="server" ID="comboBoxClientID" Text="Rad Combo Box">
            <Items>
                <telerik:RadComboBoxItem Text="Item1" Value="Item1" />
                <telerik:RadComboBoxItem Text="Item2" Value="Item2" />
            </Items>
        </telerik:RadComboBox>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

.cs:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
    {
        GridEditFormItem editform = (GridEditFormItem)e.Item;
        RadComboBox radComboBox = (RadComboBox)editform.FindControl("comboBoxClientID");
        string value = radComboBox.SelectedValue;
    }
}

Best wishes,
Vasil
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Guruvu
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Guruvu
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or