Hi,
I have a dataset that has two datatables.
In the first datatable I have EmpNo,EmpName and EmpAddress
In the second datatable I have Empno,EmpJoinda te, EmpSalary.
I want a result where I should show EmpName as the label and his/her details in the gridview
I populate a datalist with the first table, and have EmpNo as the datakeys.
Then I populate the gridview inside the datatable which has EmpNo,EmpJoinDa te and EmpAddress.
My Designer.aspx is as below
On execution I do not observe any results, and I see errors as
RowError HasErrors on the screen
I included in the gridview the bound field control as
And on execution, it throws an error stating A field or property with the name 'EmpNo' was not found on the selected data source.
I checked the "sequence" using Debug mode, and it had values in the array, which I have highlighted,
So where am I going wrong
* Results View Expanding the Results View will enumerate the IEnumerable
* [0] {System.Data.Da taRow} System.Data.Dat aRow HasErrors false bool
* ItemArray {object[2]} object[] [0] "65" object {string} [1] "A" object {string} RowError "" string RowState Added System.Data.Dat aRowState
* Table {} System.Data.Dat aTable
* Static members
* Non-Public members
I have a dataset that has two datatables.
In the first datatable I have EmpNo,EmpName and EmpAddress
In the second datatable I have Empno,EmpJoinda te, EmpSalary.
I want a result where I should show EmpName as the label and his/her details in the gridview
I populate a datalist with the first table, and have EmpNo as the datakeys.
Then I populate the gridview inside the datatable which has EmpNo,EmpJoinDa te and EmpAddress.
Code:
DataTable dt = new DataTable();
dt.Columns.Add("EmpNo");
for (int i = 65; i < 70; i++)
{
DataRow dr = dt.NewRow();
dr["EmpNo"] = i.ToString();
dt.Rows.Add(dr);
}
DataTable dt2 = new DataTable();
dt2.Columns.Add("EmpNo");
dt2.Columns.Add("EmpName");
for (int i = 65; i < 70; i++)
{
DataRow dr = dt2.NewRow();
dr["EmpNo"] = i.ToString();
dr["EmpName"] = Convert.ToChar(i);
dt2.Rows.Add(dr);
}
Datalist1.DataSource = dt;
Datalist1.DataBind();
IEnumerable<DataRow> sequence = dt2.AsEnumerable();
for (int i = 0; i < Datalist1.Items.Count; i++)
{
string EmpNo = Datalist1.DataKeys[i].ToString();
string strExpr = "EmpNo =" + EmpNo.ToString();
GridView Gridview1 = (GridView)Datalist1.Items[i].FindControl("Gridview1");
Gridview1.DataSource = sequence.Where(t => t.Field<string>("EmpNo") == EmpNo);
Gridview1.DataBind();
}
Code:
<asp:DataList ID="Datalist1" runat="server" DataKeyField="EmpNo">
<ItemTemplate>
<asp:GridView ID="Gridview1" runat="server">
</asp:GridView>
</ItemTemplate>
</asp:DataList>
RowError HasErrors on the screen
I included in the gridview the bound field control as
Code:
<asp:GridView ID="Gridview1" AutoGenerateColumns="true" runat="server">
<Columns>
<asp:BoundField DataField="EmpNo" />
</Columns>
</asp:GridView>
I checked the "sequence" using Debug mode, and it had values in the array, which I have highlighted,
So where am I going wrong
* Results View Expanding the Results View will enumerate the IEnumerable
* [0] {System.Data.Da taRow} System.Data.Dat aRow HasErrors false bool
* ItemArray {object[2]} object[] [0] "65" object {string} [1] "A" object {string} RowError "" string RowState Added System.Data.Dat aRowState
* Table {} System.Data.Dat aTable
* Static members
* Non-Public members
Comment