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

Bind combobox inside dropdown?????

2 Answers 40 Views
This is a migrated thread and some comments may be shown as answers.
shivesh
Top achievements
Rank 1
shivesh asked on 19 Oct 2010, 11:47 AM
my gridview aspx code is..

<telerik:RadGrid ID="radGrid1" runat="server" AutoGenerateColumns="False"
            OnSelectedIndexChanged="radGrid1_SelectedIndexChanged" GridLines="None"
            AllowMultiRowEdit="True" OnItemDataBound="radGrid1_ItemdatBound">
             
            <MasterTableView  AutoGenerateColumns="false">
             
                <Columns>
             
                    <telerik:GridTemplateColumn HeaderText="Product Name">
                        <EditItemTemplate>
                            <telerik:RadComboBox ID="cbo1" runat="server" AppendDataBoundItems="true" EnableLoadOnDemand="true" Width="300px" Height="100px"
                            DataValueField="product_id" AutoPostBack="true" Text='<%# Bind("Product_Name")%>' DataTextField="Product_Name" MarkFirstMatch="true" DropDownWidth="300px"></telerik:RadComboBox>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Product_rate">
                        <ItemTemplate>
                            <asp:Label ID="lblrate" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Product_Rate")%>'></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Product Quantity">
                        <EditItemTemplate>
                            <asp:TextBox ID="txtQuantity" runat="server" />
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Product Amount">
                        <EditItemTemplate>
                            <asp:TextBox ID="txtAmount" runat="server" />
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
and code behind is

for bind radgrid is
public void bindradGrid()
        {
            SqlConnection con=new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
            SqlCommand cmd=new SqlCommand("select * from product_detail",con);
            con.Open();
            SqlDataAdapter da=new SqlDataAdapter(cmd);
            DataSet ds=new DataSet();
            da.Fill(ds);
            radGrid1.DataSource=ds;
            radGrid1.DataBind();
            con.Close();
             
        }
and for item data bind is

protected void radGrid1_ItemdatBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
            {
                GridEditableItem editItem = e.Item as GridEditableItem;
                RadComboBox combo = (RadComboBox)editItem.FindControl("Product_Name");
                SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
                SqlCommand cmd = new SqlCommand("select product_id.product_name from product_detail", con);
                con.Open();
               SqlDataAdapter da = new SqlDataAdapter(cmd);
               DataTable dt = new DataTable();
               da.Fill(dt);
               radGrid1.DataSource = dt;
               radGrid1.DataBind();
 
               combo.DataTextField = "product_name";
               combo.DataValueField = "product_id";
               combo.DataBind();
                
               
            }
        }
i am using many article but i am unable to bind radgrid with radcombo plz suggest me......


thanks
shivesh

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 19 Oct 2010, 02:07 PM
Hi Shivesh,


I guess you mistyped the RadComboBox ID when accessing the control in ItemDataBound event.

Try the following code snippet:
protected void radGrid1_ItemdatBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
            {
                GridEditFormItem editItem = e.Item as GridEditFormItem;
  
                RadComboBox combo = (RadComboBox)editItem.FindControl("cbo1");
  
                SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
                SqlCommand cmd = new SqlCommand("select product_id.product_name from product_detail", con);
               con.Open();
               SqlDataAdapter da = new SqlDataAdapter(cmd);
               DataTable dt = new DataTable();
               da.Fill(dt);
    
               combo.DataTextField = "product_name";
               combo.DataValueField = "product_id";
               combo.DataBind();               
            }
        }


Thanks,
Princy.
0
shivesh
Top achievements
Rank 1
answered on 22 Oct 2010, 10:54 AM
Hi Princy,

I have used your code but dropdownlist not displaying value. now code is..
<telerik:RadGrid ID="radGrid1" runat="server" AutoGenerateColumns="False" GridLines="None"
            AllowMultiRowEdit="True" OnItemDataBound="radGrid1_DataBound" OnNeedDataSource="radGrid1_NeedDataSource">
            <MasterTableView AutoGenerateColumns="false">
                <Columns>
                    <telerik:GridTemplateColumn HeaderText="Product Name">
                        <EditItemTemplate>
                            <asp:DropDownList ID="ddl1" runat="server" AutoPostBack="true" DataValueField="Product_Id"
                                DataTextField="Product_Name">
                            </asp:DropDownList>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Product_rate">
                        <ItemTemplate>
                            <asp:Label ID="lblrate" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Product_Rate")%>'></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Product Quantity">
                        <ItemTemplate>
                            <asp:TextBox ID="txtQuantity" runat="server" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Product Amount">
                        <ItemTemplate>
                            <asp:TextBox ID="txtAmount" runat="server" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
protected void radGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
            SqlDataAdapter da = new SqlDataAdapter("select * from product_detail", connection);
            DataTable dt = new DataTable();
            connection.Open();
            try
            {
                da.Fill(dt);
            }
            finally
            {
                connection.Close();
            }
            radGrid1.DataSource = dt.DefaultView;
        }
 
 
  protected void radGrid1_DataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
 
 
                GridEditableItem item = e.Item as GridEditableItem;
                DropDownList list =(DropDownList)item.FindControl("ddl1");
                SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
                SqlDataAdapter da = new SqlDataAdapter("select product_id,product_name from product_detail", connection);
                DataTable datatable = new DataTable();
                da.Fill(datatable);
                list.DataTextField = "product_name";
                list.DataValueField = "product_id";
                list.DataBind();
              }
             
        }
Asked by
shivesh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
shivesh
Top achievements
Rank 1
Share this question
or