我想以自定义表格式显示SQL数据库中的数据。所以基本上这就是我想要实现的目标:
A。要在网格视图中显示SQL表中的所有条目,并在每行旁边显示一个view
按钮
B。点击view
按钮以在新网页中显示以下内容
______________________________________
| Customer Info |
----------------------------------------
|Customer Name: "From DB Table" |
|Address: "From DB Table" |
----------------------------------------
然后在上面的那个下面的下一个table
______________________________________
| Customer Network |
----------------------------------------
|Network Location: "From DB Table" |
|APs: "From DB Table" |
----------------------------------------
以上所有内容均来自我的SQL DB表中的一个ID
。所以我想将其分解为几个部分,以显示SQL表中的所有数据
我还没有任何代码,因为我不确定该怎么做。
总结一下:
页面加载后,将在gridview
中显示数据库中的所有条目,并在每行旁边显示一个视图按钮
然后,当用户单击view
按钮时,它将打开一个带有上表的新页面。
谢谢
代码
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>
然后隐藏代码
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;
}
}
}
这是我的网络应用中其他部分的代码。我可以使用相同的代码进行一些更改,但是如何添加“查看”按钮并实现上述问题?