Pratik Patel
Pratik Patel

Reputation: 11

Infragistics WebDataGrid DropDownList lose state in post back

I have TemplateDataField in which contain DropDownList control in WebDataGrid. This DropDownList bind in row initialize event of the WebDataGrid and every post back Grid binds again using DataTable which is stored in a view state but one point on checkbox change event data getting from database and bind the grid ,till that everything working fine. But when I click on button(save button which get all data from grid and save it into database) than no item found in DropDownList, So what is an issue in that?

All controls are in Update panel.

Upvotes: 1

Views: 624

Answers (1)

Zdravko Kolev
Zdravko Kolev

Reputation: 1587

I have two suggestions, bind the list on ItemTemplate creation instead of RowInitialize server event, and also if you are creating the templates dynamically, use Page_Init.

Code snippet:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Init(object sender, EventArgs e)
    {
        TemplateDataField FreightField = new TemplateDataField();
        FreightField.ItemTemplate = new CustomTemplate();
        FreightField.VisibleIndex = 2;
        FreightField.Key = "Freight";

        TemplateDataField ShippedDateField = new TemplateDataField();
        ShippedDateField.ItemTemplate = new CustomTemplate2();
        ShippedDateField.VisibleIndex = 3;
        ShippedDateField.Key = "ShippedDate";

        if (this.WebDataGrid1.Columns.FromKey("Freight") != null)
        {
            ((TemplateDataField)this.WebDataGrid1.Columns["Freight"]).ItemTemplate = new CustomTemplate();
            ((TemplateDataField)this.WebDataGrid1.Columns["ShippedDate"]).ItemTemplate = new CustomTemplate2();

        }
        else
        {
            this.WebDataGrid1.Columns.Add(FreightField);
            this.WebDataGrid1.Columns.Add(ShippedDateField);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

public class CustomTemplate : ITemplate
{
    public void InstantiateIn(Control container)
    {
        WebDropDown wdd = new WebDropDown();
        wdd.ID = "WebDropDown1";
        wdd.Width = Unit.Pixel(200);
        wdd.Items.Add(new DropDownItem("1", "1"));
        wdd.Items.Add(new DropDownItem("2", "2"));
        wdd.Items.Add(new DropDownItem("3", "3"));

        wdd.ClientEvents.SelectionChanged = "ctl00_WebDropDown1_SelectionChanged";

        container.Controls.Add(wdd);
    }

    protected void btn_Click(object sender, EventArgs e)
    {
        var temp = 0;
    }
}

public class CustomTemplate2 : ITemplate
{
    public void InstantiateIn(Control container)
    {
        WebDropDown wdd = new WebDropDown();
        wdd.ID = "WebDropDown2";
        wdd.Width = Unit.Pixel(200);
        wdd.Items.Add(new DropDownItem("4", "4"));
        wdd.Items.Add(new DropDownItem("5", "5"));
        wdd.Items.Add(new DropDownItem("6", "6"));


        container.Controls.Add(wdd);
    }
}

Upvotes: 0

Related Questions