如何使用vb.net中的dropdownlist插入数据 [英] how to insert data using dropdownlist in vb.net
本文介绍了如何使用vb.net中的dropdownlist插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想问一下,如何将所选数据插入到sql server中。
fyi,我使用visual studio 2008
这是我的html代码,< br $>
i want to ask, how to insert selected data into sql server.
fyi, I'm use visual studio 2008
this my html code,
<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 here the code behind
Dim TagAdd As DropDownList = CType(control.FindControl("ddlTagAdd"), SelectedItem).Text
cmd.CommandText = "INSERT INTO [ModuleDetails](ModuleName, SubModule, TagAdd, TagEdit, TagDelete) VALUES(@ModuleName, @SubModule, @TagAdd, @TagEdit, @TagDelete)"
cmd.Parameters.AddWithValue("@TagAdd", TagAdd.SelectedItem)
但是,错误显示未声明SelectedItem(在Dim行)。
你能帮我讲一下如何申报下拉列表吗?
however, the error shows that SelectedItem is not declared(at Dim line).
can you help me on how to declared dropdownlist?
推荐答案
HTML code
HTML code
<asp:templatefield headertext="Add" xmlns:asp="#unknown">
<itemtemplate>
<%# Eval("TagAdd") %>
</itemtemplate>
<footertemplate>
<asp:dropdownlist id="ddlTagAdd" 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>
代码背后
code behind
Dim TagAdd As String = CType(control.FindControl("ddlTagAdd"), DropDownList).SelectedValue.ToString
cmd.CommandText = "INSERT INTO [ModuleDetail](ModuleName, SubModule, TagAdd, TagEdit, TagDelete) VALUES(@ModuleName, @SubModule, @TagAdd, @TagEdit, @TagDelete)"
cmd.Parameters.AddWithValue("@TagAdd", TagAdd.ToString)
这篇关于如何使用vb.net中的dropdownlist插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文