I want to display data from my SQL database in a custom table format. So basically this is what I would like to achieve:
A. To display all entries in SQL table in a gridview with a view button next to each row
B. Click on the view button to display the below in a new web page
______________________________________
| Customer Info |
----------------------------------------
|Customer Name: "From DB Table" |
|Address: "From DB Table" |
----------------------------------------
Then the next table below the one above
______________________________________
| Customer Network |
----------------------------------------
|Network Location: "From DB Table" |
|APs: "From DB Table" |
----------------------------------------
All of the above is from one ID in my SQL DB table. So I want to break it up into sections to display all the data in the SQL Table
I don't have any code yet as I am not sure on how to do this.
To sum up:
When the page loads it the shows all the entries in the database in a gridview with a view button next to each row
Then when the user clicks on the view button it opens a new page with the above table.
Thanks
CODE
GridView
<asp:GridView ID="GridView1" runat="server" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
Then Code Behind
GridView1.DataSource = GetData();
GridView1.DataBind();
}
}
}
DataTable GetData()
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["OfficeConnection"].ConnectionString))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("SELECT DisplayName 'Display Name', Replace(PrimaryEmailAddress,'SMTP:', ' ') 'Email Address', Replace(Licenses,'reseller-account:', ' ') 'License Type', LastPasswordChangeTimestamp 'Last Password Reset' FROM Consulting ", con))
{
for (int i = dt.Rows.Count - 1; i >= 0; i--)
{
if (dt.Rows[i][1] == DBNull.Value)
dt.Rows[i].Delete();
}
dt.AcceptChanges();
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
adpt.Fill(dt);
}
}
return dt;
}
}
}
This is some code from a different section in my web app. I can use the same code with a few changes, but how do I add the View button and to achieve the above question?