错误如下:Exception Details: System.ArgumentException: Item has already been added.
Key in dictionary: 'City' Key being added: 'City'说明:如果去掉前台的SelectedValue='<%# Bind("City") %>'
,则编辑Dropdownlist时不显示City在数据库中的值,所有的都显示beijing
代码如下:
前台: <EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
SelectedValue='<%# Bind("City") %>' AppendDataBoundItems="True">
<asp:ListItem>beijing</asp:ListItem>
<asp:ListItem>shanghai</asp:ListItem>
<asp:ListItem>guangzhou</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>后台:
protected void DetailsView1_ItemUpdating1(object sender,
DetailsViewUpdateEventArgs e)
{
string strCity =
((DropDownList)DetailsView1.Rows[2].Cells[1].FindControl("DropDownList1")).SelectedValue.ToString(); e.NewValues.Add("City", strCity);
}我把代码也放上去,谢谢帮我看一下!
Key in dictionary: 'City' Key being added: 'City'说明:如果去掉前台的SelectedValue='<%# Bind("City") %>'
,则编辑Dropdownlist时不显示City在数据库中的值,所有的都显示beijing
代码如下:
前台: <EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
SelectedValue='<%# Bind("City") %>' AppendDataBoundItems="True">
<asp:ListItem>beijing</asp:ListItem>
<asp:ListItem>shanghai</asp:ListItem>
<asp:ListItem>guangzhou</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>后台:
protected void DetailsView1_ItemUpdating1(object sender,
DetailsViewUpdateEventArgs e)
{
string strCity =
((DropDownList)DetailsView1.Rows[2].Cells[1].FindControl("DropDownList1")).SelectedValue.ToString(); e.NewValues.Add("City", strCity);
}我把代码也放上去,谢谢帮我看一下!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货