Asp.net listview内的下拉列表插入项模板将null传递给数据库
目前我有一个dropdownlist,它有自己的sqldatasource来填充dropdownlist。 ddl位于listviews中,listviews还具有它在sqldatasource上的插入项模板。 但是,单击“插入”时,传递给数据库的值为空Asp.net listview内的下拉列表插入项模板将null传递给数据库,asp.net,Asp.net,目前我有一个dropdownlist,它有自己的sqldatasource来填充dropdownlist。 ddl位于listviews中,listviews还具有它在sqldatasource上的插入项模板。 但是,单击“插入”时,传递给数据库的值为空 <InsertItemTemplate> <tr style=""> <td>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
</td>
<td>
</td>
<td>
<asp:TextBox ID="td_t_idTextBox" runat="server" Text='<%# Bind("td_t_id") %>' Enabled="false" />
</td>
<td>
<asp:DropDownList ID="DropDownList2iit" runat="server" DataSourceID="SqlDataSource30"
DataTextField="document_name" DataValueField="document_id"
SelectedIndex='<%# Bind("td_docid") %>'>
</asp:DropDownList>
</td>
</tr>
</InsertItemTemplate>
它的工作原理和它应该的一样。你可以像贝娄一样尝试。(我百分之百肯定,但希望一切顺利)
这个问题很老了,但可能会对某人有所帮助 您正在将下拉列表的值绑定到selectedindex属性。它应该绑定到SelectedValue。不需要为此编写代码 替换:
SelectedIndex='<%# Bind("td_docid") %>'>
SelectedIndex=''>
与
SelectedValue=''
感谢您用答案更新问题。
protected void ListView2_OnItemInserting(object sender, EventArgs e)
{
string sv = ((DropDownList)ListView2.InsertItem.FindControl("DropDownList2iit")).SelectedValue;
SqlDataSource31.InsertParameters.Add("document_id", sv);
}
protected void ListView2_OnItemInserting(object sender, EventArgs e)
{
string sv = ((DropDownList)e.Item.FindControl("DropDownList2iit")).SelectedValue;
SqlDataSource31.InsertParameters.Add("document_id", sv);
}
SelectedIndex='<%# Bind("td_docid") %>'>
SelectedValue= '<%# Bind("td_docid") %>'