尝试在asp.net中创建下拉列表时出错。希望你们能帮忙,因为我不知道还有什么可以尝试..
错误:" system.data.datarowview'不包含名称为' Suppstatus'。"的财产,听起来像拼写错误但我已经检查过。
模板代码:
<asp:TemplateField>
<ItemTemplate>
<asp:Label Text='<%#Eval("Suppstatus") %>' Visible="false" ID="lblsuppStatus" runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddlSupStatus"> </asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
代码背后:
protected void grvSupplierStatus_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow && GridView1.EditIndex == e.Row.RowIndex)
{
DropDownList ddlSupStatus = (DropDownList)e.Row.FindControl("ddlSupstatus");
Label lblsuppstatus = (Label)e.Row.FindControl("lblsuppStatus");
DataSet ds = new DataSet();
ds = GetYesNoValue("Suppstatus");
DataTable dt = new DataTable();
dt = ds.Tables[0];
ddlSupStatus.DataSource = dt;
ddlSupStatus.DataTextField = "Suppstatus";
ddlSupStatus.DataValueField = "Suppstatus";
ddlSupStatus.DataBind();
ddlSupStatus.Items.FindByValue(lblsuppstatus.Text).Selected = true;
}
}
catch (Exception ex)
{
}
}
public DataSet GetYesNoValue(string ColumnName)
{
DataTable dtVal = new DataTable();
DataColumn column;
DataRow row;
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = ColumnName;
dtVal.Columns.Add(column);
DataSet dsVal = new DataSet();
dtVal.Rows.Add("--Select--");
dtVal.Rows.Add("Yes");
dtVal.Rows.Add("No");
dsVal.Tables.Add(dtVal);
return dsVal;
}
答案 0 :(得分:0)
您正在使用迂回方法插入数据。你也可以
替换
<asp:DropDownList runat="server" ID="ddlSupStatus" ></asp:DropDownList>
带
<asp:DropDownList runat="server" ID="ddlSupStatus" Selected='<%# Bind("Suppstatus") %>'>
<asp:ListItem Text="--Select--" Value="--Select--"></asp:ListItem>
<asp:ListItem Text="Yes" Value="Yes"></asp:ListItem>
<asp:ListItem Text="No" Value="No"></asp:ListItem>
</asp:DropDownList>
没有任何动作代码隐藏