Retrieving DataItem from RepeaterItem after data binding (during event processing)

I am trying to find a way to do something that, in my opinion, should be possible, but I just don’t know what I hope, someone can push me a little :)

I use data binding in ASP.NET (viewstate is disabled - so using controlstate for a few things here and there) to render a repeater (repeataterPriceClasses) that has a repeater in each itemtemplate (repeaterPriceBands). It basically displays a table of some text and a drop-down list in each cell.

I am trying to find a way to list repeataterOuter inside a button event handler to give me a list of all the initially related items that now have a drop-down list with a value> 0, however that is a value.

public Dictionary<Price, int> SelectedPrices
{
    get
    {
        var sel = new Dictionary<Price, int>();
        foreach(RepeaterItem itemClass in repeaterPriceClasses.Items)
        {
            var repeaterPriceBands = itemClass.FindControl("repeaterPriceBands") as Repeater;

            foreach(RepeaterItem itemBand in repeaterPriceBands.Items)
            {
                var context = (Price)itemBand.DataItem;
                var listQty = itemBand.FindControl("listQty") as DropDownList;

                if(listQty.SelectedValue.ToInt32() > 0)
                {
                    sel.Add(context, listQty.SelectedValue.ToInt32());
                }
            }
        }
        return sel;
    }
}

Now this fails because itemBand.DataItem is always null after the data binding is complete.

What technique should I use to get around this?

  • Hidden field with primary keys in it (not ideal, how can one be abused and add weight to the page)

  • Searching from source cached index-based data (just seems wrong)

  • or something else / better ...?

EDIT: Is there any additional information I could provide to help you get an answer?

+3
1

HTML- ItemDataBound, DataItem.

ddlSomething.Attributes["Attribute1"] = dataItemObject.PropertyName;

[] , , JSON, , .

var repeaterItemAttributes = [ { Prop1: val1, Prop2: val2, ... }, { ... }, ... ]

, , XHTML ( ). , . , , . [/Edit]

+1

Source: https://habr.com/ru/post/1706406/


All Articles