Can anyone please help me i have in ASP.NET A Table called : info , with 3 columns : id,name,code
I want on a page called Default.aspx to have a checkboxlist that shows the table's Columns and when the user selects what columns he wants to see , then he presses a button to redirect him to Another Page and be shown in a Gridview (the gridview results to be show in a different page it's very important)
Page 1 :
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" BackColor="#FFFFCC" Height="165px" Width="155px">
<asp:CheckBoxList ID="CheckBoxList1" runat="server"></asp:CheckBoxList>
<br />
</asp:Panel>
</div>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" style="height: 26px" Text="Button" />
<br />
</form>
Code behind Page 1 :
SqlConnection con = new SqlConnection("Server=.\\SQLEXPRESS;Database = ProiectWeb; Integrated Security=True");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
loadData();
}
}
private void loadData()
{
cmd.Connection = con;
cmd.CommandText = "SELECT column_name FROM information_schema.columns WHERE table_name ='info' ORDER BY ordinal_position";
con.Open();
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
CheckBoxList1.Items.Add(reader[0].ToString());
}
}
reader.Close();
con.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
}
Page 2 :
<asp:Panel ID="Panel2" runat="server" Height="302px" Width="278px">
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" style="margin-left: 0px">
</asp:GridView>
</asp:Panel>
Code Behind Page 2 :
SqlConnection con = new SqlConnection("Server=.\\SQLEXPRESS;Database = ProiectWeb; Integrated Security=True");
SqlCommand cmd = new SqlCommand();
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
cmd.Connection = con;
loadGrid("SELECT * FROM info");
}
}
public void loadGrid(string query)
{
DataSet data = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(query,con);
adapter.Fill(data);
GridView1.DataSource = data;
GridView1.DataBind();
}