I am trying to add two list to one list. i am using linq to populate the list but it is showing some error. And i have to bind the new list contain two other list to grid view.
The follwoing is my code and it is working fine
DataTable table;
protected void Page_Load(object sender, EventArgs e)
{
bind();
}
public void bind()
{
SqlConnection conn = new SqlConnection(@"Data Source=CLAYSYSCH0028\Sharepoint;Initial Catalog=ShankarMS;Integrated Security=True");
conn.Open();
SqlCommand comm = new SqlCommand();
comm.CommandText = "select * from UserDetails";
comm.Connection = conn;
SqlDataAdapter adapter = new SqlDataAdapter(comm);
DataSet set = new DataSet();
adapter.Fill(set);
table = set.Tables[0];
//Stack<support> stack = new Stack<support>();
List<int> first = new List<int>((from x in table.AsEnumerable() where x.Field<int>("ID") != 177 select x.Field<int>("ID")).ToArray());
List<int> second = new List<int>((from x in table.AsEnumerable() where x.Field<int>("ID") == 180 select x.Field<int>("ID")).ToArray());
List<int> main = new List<int>();
if (second.Count > 0)
{
main.InsertRange(0, second);
main.InsertRange(1, first);
}
else
{
main.InsertRange(0, first);
}
//stack.AddRange((from x in table.AsEnumerable() where x.Field<int>("ID") != 177 select x.Field<int>("ID")).ToList());
grid.DataSource = main;
grid.DataBind();
}
This is my grid
<asp:GridView ID="grid" runat="server" ClientIDMode="Inherit" >
</asp:GridView>
But my requirment is i have to declare the first and second list as a custom class type.
My
custom class is
public class support
{
public int id
{
get;
set;
}
public string Name
{
get;
set;
}
}
And i have to bind the new list main to grid. And i have to bind the values to template field in grid view.
And that grid is like this
<asp:GridView ID="lst" runat="server" ClientIDMode="Inherit">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbl" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Please help me.