none
DropDownListe in GridView Items.Insert RRS feed

  • Frage

  • Hallo Leute,

    ich möchte eine DropDownListe innerhalb ein GridView   mit items ausfüllen

       <asp:GridView ID=

    ....

    <asp:TemplateField HeaderText="Verwendungszweck" HeaderStyle-Width= "140px" ControlStyle-Width= "140px"> <ItemTemplate> <asp:DropDownList ID="ddlVerwendungszweck" runat="server" Width="140px" </asp:DropDownList> </ItemTemplate> </asp:TemplateField>

    gibt es eine möglichkeit sowas wie .Items.Insert

    z.B.  ddlVerwendungszweck.Items.Insert(1, new ListItem("Ja", "1")); // so ist die ddl nicht ereichbar

    Beste Grüsse
    Lubb

    Donnerstag, 9. Februar 2012 13:11

Antworten

  • Die Lösung Wäre:

            // DropDownList in GridView Füllen
            private void BindDropDownList_GV()
            {
                int index = 0;
                foreach (GridViewRow gv in GV.Rows)
                {
                    string MethodID = " DET 01CGVRC - ";
    
                    string sql = "SELECT ID, Wert FROM Werte ";
                    SqlDataReader ddlValues = GetDataReader(....);
    
                    DropDownList iconUsers = new DropDownList();
                    iconUsers = (DropDownList)gvArtikelBestellung.Rows[index].FindControl("ddl");
                    iconUsers.DataSource = ddlValues;
                    iconUsers.DataValueField = "ID";
                    iconUsers.DataTextField = "Wert";
    
                    iconUsers.DataBind();
                    index++;
                } 
            }

    • Als Antwort markiert lubb Mittwoch, 15. Februar 2012 14:24
    • Tag als Antwort aufgehoben lubb Mittwoch, 15. Februar 2012 14:24
    • Als Antwort markiert lubb Mittwoch, 15. Februar 2012 14:24
    Dienstag, 14. Februar 2012 07:20