You must Sign In to post a response.
  • Category: Silverlight

    Binding data from database to datagrid combo box

    HI,

    I have a combo box in datagrid. I need to get data from database and on page load I have to bind data to combobox datagrid.

    Any code or links...


    Regards,
  • #753477
    Hi,

    If you want to bind data to your combobox inside data controls. Then you need to perform onitemdatabound event and bind your combobox.

    EX:

    protected void dg_OnItemDataBound(object sender,DataGridItemEventArgs e)
    {
    if((e.Item.ItemType == ListItemType.Item) ||
    (e.Item.ItemType == ListItemType.AlternatingItem))
    {
    ComboBox cmb=(ComboBox)e.Item.FindControl("cmb1");
    cmb.DataSource=ds;
    cmb.DataTextField="text";
    cmb.DataValueField="value";
    cmb.DataBind();
    }
    }


    Try something like above to achieve your goal..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #753485
    You can use the Data grid Item Data bound event and there you can select the COntrol and can bind,

    Below is a sample code given for how to use that event



    puiblic void Item_Bound(Object sender, DataListItemEventArgs e)
    {

    if (e.Item.ItemType == ListItemType.Item ||
    e.Item.ItemType == ListItemType.AlternatingItem)
    {

    Label PriceLabel = (Label)e.Item.FindControl("PriceLabel");
    PriceLabel.BackColor = System.Drawing.Color.Red;
    }

    }

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM


  • Sign In to post your comments