<asp:DataList ID="dl_company" runat="server" RepeatLayout="Table" RepeatColumns="5"
RepeatDirection="Horizontal" CellPadding="4" >
<ItemTemplate>
<h2>
<asp:Label ID="lbl_domain" runat="server" Text='<%# Eval("first_letter")%>'></asp:Label>
</h2>
</ItemTemplate>
<asp:GridView ID="dg1" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField HeaderText= "" HeaderStyle-BackColor="#E5E5E5"
HeaderStyle-Height="20px" ShowHeader="False">
<ItemTemplate>
<%# Eval("PERSISTED")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
背后的代码
private void grddatabinding()
{
DataTable dt = new Code.User().getcdomain();
dl_company.DataSource = dt;
dl_company.DataBind();
for (int i = 0; i < dl_company.Items.Count; i++)
{
Label lbl_domain = (Label)dl_company.Items[i].FindControl("lbl_domain");
DataTable dt2 = new Code.User().getcompanycard(lbl_domain.Text);
if (dt2.Rows.Count != 0)
{
GridView dg1 = (GridView)dl_company.Items[i].FindControl("dg1");
dg1.DataSource = dt2;
dg1.DataBind();
}
}
如何将Gridview标题文本设为= Label Value (lbl_domain)
A到Z是DataList标签值
Gridview给我字母表列表,即
“A”数据列表标签
空白(标题)Gridview
apple.com
arkk.com
相同
我需要这样
- “A”(数据列表标签 - 不是这个)
“A”Gridview像这样 - 模板标题(但值应来自DataList)
apple.com
arkk.com