With custom HTML5 attributes, you can set the value of the drop-down list to the data attribute, and then set it as the selected value after the drop-down list with data binding, I linked the drop-down menu using asp: ObjectDataSource
<asp:Repeater runat="server" ID="myRepeater> <ItemTemplate> <asp:DropDownList runat="server" CssClass="fullSelect" ID="degree_dropdown" AppendDataBoundItems="true" SetValue='<%#DataBinder.Eval(Container.DataItem,"degreeCode")%>' datasourceid="dsCategory" datatextfield="degree" datavaluefield="code" onprerender="DropDownDataBinding"> <asp:ListItem Text="Select Degree" /> </asp:DropDownList> <asp:ObjectDataSource ID="dsCategory" runat="server" SelectMethod="LoadDegree" TypeName="WebApplication.WebForm1" /> </ItemTemplate> </asp:Repeater>
CodeBehind
protected void DropDownDataBinding(object sender, EventArgs e) //Method to set the selected value on Category dropdown inside repeater { DropDownList sel = (DropDownList)sender; sel.Value = sel.Attributes["SetValue"]; ListItem li = new ListItem("<< Select >>", ""); sel.Items.Insert(0,li); } protected DataTable LoadDegree() { DataTable dt = new DataTable(); dt = degrees; //a datatable return dt; }
Linking your repeater will remain the same
sohaiby
source share