将下拉列表绑定到网格视图的问题 [英] Problem with binding a Dropdown list to the Grid View
本文介绍了将下拉列表绑定到网格视图的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在运行时将数据源绑定到Grid视图中的DropDownList时,出现以下错误,指出该错误
"DataBinding:" System.Data.DataRowView"不包含名称为"Dept_ID"的属性.
我使用了以下代码..请其紧急我亲爱的朋友们...
问候
Sushil Dharmar
.aspx页面
While Binding a DataSource to an DropDownList in the Grid View at Run time I get the Following error specifying that
" DataBinding: ''System.Data.DataRowView'' does not contain a property with the name ''Dept_ID''. "
I had used the following code.. Please Its Urgent My Dear Friends...
Regards
Sushil Dharmar
.aspx Page
<asp:GridView ID="grdEmployee" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnRowDataBound="grdEmployee_RowDataBound">
<Columns>
<asp:BoundField DataField="EMP_ID" HeaderText="EMP_ID" />
<asp:BoundField DataField="EMP_NAME" HeaderText="EMP_NAME" />
<asp:BoundField DataField="SALARY" HeaderText="SALARY" />
<asp:BoundField DataField="HIRE_DATE" HeaderText="HIRE_DATE" />
<asp:TemplateField HeaderText="DEPT_ID">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="ddlDeptId" runat="server" AutoPostBack="True">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
.Cs页面
.Cs Page
protected void Bind()
{
_str = " SELECT EMP_ID,EMP_NAME,SALARY,HIRE_DATE from Employee ";
adp = new SqlDataAdapter(_str, con);
ds = new DataSet();
adp.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
grdEmployee.DataSource = ds.Tables[0];
grdEmployee.DataBind();
}
}
protected void grdEmployee_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlDeptId = (DropDownList)e.Row.FindControl("ddlDeptId");
_strdrop = " SELECT distinct Dept_ID from Department ";
adpdrp = new SqlDataAdapter(_strdrop, con);
dsdrp = new DataSet();
adpdrp.Fill(dsdrp);
ddlDeptId.DataSource = dsdrp;
ddlDeptId.DataTextField = "Dept_ID";
ddlDeptId.DataValueField = "Dept_ID";
ddlDeptId.ID = "Dept_ID";
ddlDeptId.DataBind();
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
推荐答案
hi,
试试这个
hi ,
try this
ddlDeptId.DataSource = ds.Tables[0];
ddlDeptId.DataTextField = "Dept_ID";
ddlDeptId.DataValueField = "Dept_ID";
ddlDeptId.ID = "Dept_ID";
ddlDeptId.DataBind();
最好的问候
米特瓦里(M.Mitwalli)
best regards
M.Mitwalli
这篇关于将下拉列表绑定到网格视图的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文