farahinsamsudin 0 Newbie Poster

hi, I want to ask about how to declare dropdownlist in vb.net. actually I'm a newbie to this vb.net language. I'm try to insert selected item from dropdownlist into database. but the data is not inserted in the table. and I've try to change the code at dropdownlist area. but it shows syntax error. Here my html code:

<pre lang="HTML"> <asp:TemplateField HeaderText="Add">
            <ItemTemplate>
                <%# Eval("TagAdd") %>
            </ItemTemplate>
            <FooterTemplate>
                <asp:DropDownList ID="TagAdd" runat="server" AutoPostBack="True"   
DataTextField="TagAdd" DataValueField="TagAdd">
                <asp:ListItem Value="0">Select Action</asp:ListItem>  
                <asp:ListItem Value="True">Enable</asp:ListItem>
                <asp:ListItem Value="False">Disable</asp:ListItem>
                </asp:DropDownList>
            </FooterTemplate>
        </asp:TemplateField>

and this is the code behind

Dim TagAdd As DropDownList = CType(control.FindControl("ddlTagAdd"), DropDownList)SelectedItem.Text

cmd.CommandText = "INSERT INTO [ModuleDetails](ModuleName, SubModule, TagAdd, TagEdit, TagDelete) VALUES(@ModuleName, @SubModule, @TagAdd, @TagEdit, @TagDelete)"

cmd.Parameters.AddWithValue("@TagAdd", TagAdd.SelectedItem)

so the error show the Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.DropDownList'
this error refer to this line.

Dim TagAdd As DropDownList = CType(control.FindControl("ddlTagAdd"), DropDownList)SelectedItem.Text

I hope you guys can help me to declare the dropdownlist

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.