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

Combo Box Record binding in Edit Mode

1 Answer 140 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ranganath
Top achievements
Rank 1
Ranganath asked on 28 Jul 2008, 01:08 PM

Hi,

In RadGird I have taken one RadComboBox, in that I have taken the thins as follow

<telerik:RadGrid ID="rg_AddPorts" runat="server" AllowPaging="True" Skin="Default"

                                GridLines="Horizontal" PageSize="10" Width="100%" OnNeedDataSource="rg_AddPorts_NeedDataSource"

                                OnInsertCommand="rg_AddPorts_InsertCommand" OnItemDataBound="rg_AddPorts_ItemDataBound"

                                OnUpdateCommand="rg_AddPorts_UpdateCommand">

<MasterTableView CommandItemDisplay="TopAndBottom" AutoGenerateColumns="false" DataKeyNames="Port_PortNo"

                                    EditMode="EditForms" CommandItemSettings-AddNewRecordText="Add Ports">

<Columns>

 

………

</Columns>

<EditFormSettings EditFormType="Template">

<EditColumn UniqueName="EditCommandColumn1">

                                        </EditColumn>

                                        <FormTemplate>

                                            <!-- Grid Table Designing->

 <table cellpadding="0" cellspacing="0" border="0" width="100%" class="TblMaster">

<tr>

<td>

<telerik:RadComboBox ID="rcbxCity" runat="server" Height="190px" Width="127px" MarkFirstMatch="true"

                                                            EnableLoadOnDemand="true" HighlightTemplatedItems="true" DataTextField="Place_City"

                                                            DataValueField="Place_No" DropDownWidth="300">

<HeaderTemplate>

<table style="width: 375px" cellspacing="0" cellpadding="0">

<tr>

<td style="width: 125px;">

                                                                            City

</td>

<td style="width: 125px;">

                                                                            State

</td>

<td style="width: 125px;">                                                                            Country

</td></tr></table>                                                            </HeaderTemplate>                                                            <ItemTemplate>                                                              <table style="width: 375px" cellspacing="0" cellpadding="0">                                                                    <tr>                                                                        <td style="width: 125px;" class="comboItemCell">                                                                            <div class="comboItem">                                                                                <%# DataBinder.Eval(Container.DataItem, "place_City")%>                                                                            </div>                                                                        </td>                                                                        <td style="width: 125px;" class="comboItemCell">                                                                            <div class="comboItem">                                                                                <%# DataBinder.Eval(Container.DataItem, "place_State")%>                                                                            </div>                                                                        </td>                                                                        <td style="width: 125px;" class="comboItemCell">                                                                            <div class="comboItem">                                                                                <%# DataBinder.Eval(Container.DataItem, "place_Country")%>                                                                            </div>                                                                        </td>                                                                    </tr></table>                                                            </ItemTemplate>                                                        </telerik:RadComboBox>                                                    </td>

 

protected void rg_AddPorts_ItemDataBound(object sender, GridItemEventArgs e)

    {

        if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))

        {

            GridEditFormItem item1 = (GridEditFormItem)e.Item;

 

            RadComboBox rcbxPortCity = item1.FindControl("rcbxCity") as RadComboBox;

            DataSet ds=BO_AddPorts.Fill_PortCity();

            rcbxPortCity.DataSource = ds;

            rcbxPortCity.DataBind();

          

            

        }

    }

And when I click “AddNew Record”Button on RadGird its Biding Perfectly. But when I want to Edit Records then I am nt able to Bind Corresponding record

Edit Mode



This time I am n table to bind The corresponding record.

Here I am taking this PlaceNo,City,State,country in to separate table and Bidning like this. Pls Guide me how to Bind Exact Inserted record when I will perform Edit Mode.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Jul 2008, 07:51 AM
Hi Ranganath,

I tried the following code snippet to bind a RadCombox in edit mode and insert mode. It is working as expected.

CS:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode) && (!e.Item.OwnerTableView.IsItemInserted)) 
        { 
 
 
            GridEditFormItem edititem = (GridEditFormItem)e.Item; 
            RadComboBox combo = (RadComboBox)edititem.FindControl("RadComboBox1"); 
 
            conn.Open(); 
            SqlDataAdapter adp = new SqlDataAdapter("select * from NewTable1", conn); 
            DataTable dt1 = new DataTable(); 
            adp.Fill(dt1); 
            combo.DataSource = dt1
            combo.DataBind(); 
            conn.Close(); 
        } 
        else if (e.Item is GridEditFormInsertItem && (e.Item.OwnerTableView.IsItemInserted)) 
        { 
            GridEditFormInsertItem insertitem = (GridEditFormInsertItem)e.Item; 
            RadComboBox combo = (RadComboBox)insertitem.FindControl("RadComboBox1"); 
 
            conn.Open(); 
            SqlDataAdapter adp = new SqlDataAdapter("select * from NewTable2", conn); 
            DataTable dt2 = new DataTable(); 
            adp.Fill(dt2); 
            combo.DataSource = dt2
            combo.DataBind(); 
            conn.Close(); 
 
        } 
 
    } 


ASPX:
<EditFormSettings EditFormType="Template" >  
                <FormTemplate> 
                    <telerik:RadComboBox ID="RadComboBox1" runat="server"
                    </telerik:RadComboBox> 
                </FormTemplate> 
        </EditFormSettings> 



Thanks
Shinu.
Tags
Grid
Asked by
Ranganath
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or