Getting DropDownList values in a repeater

久未见 提交于 2019-12-12 05:44:09

问题


ASPX PAGE:

 <asp:Repeater ID="GeneralRepeater" runat="server" 
 OnItemDataBound="GeneralRepeater_OnItemDataBound">
   <ItemTemplate>
     <tr>
      <td>
       DxPoc:
         <asp:DropDownList ID="GeneralDDL" DataTextField="DiagnosisCode" 
         DataValueField="DiagnosisCode" runat="server" />
     </td>
    </tr>
   </ItemTemplate>
</asp:Repeater>

CODE BEHIND:

protected void GeneralRepeater_OnItemDataBound(object sender,
                                               RepeaterItemEventArgs e)


     {
            if (e.Item.ItemType == ListItemType.Item ||
                e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DropDownList myDDL = (DropDownList)e.Item.FindControl("GeneralDDL");
                Diagnosis oDiagnosis = new Diagnosis();
                DataView dv = new DataView(oDiagnosis.GetDiagnosis());
                myDDL.DataSource = dv;
                myDDL.DataTextField = "DiagnosisCode";
                myDDL.DataValueField = "DiagnosisCode";
                myDDL.DataBind();

            }
        }

The given shown above is not working properly. During page load it nothing happens on the dropdownlist inside the repeater.

QUESTIONS:

a.) How I'll get the values of my dropdownlist with list of objects inside the repeater?

thanks!


回答1:


if(!IsPostBack)
{
    BindRepeater();
}


来源:https://stackoverflow.com/questions/6039318/getting-dropdownlist-values-in-a-repeater

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!