存储超链接列表

时间:2014-07-30 17:22:11

标签: asp.net gridview hyperlink datatable

我有一个包含网格视图的aspx页面。网格视图的数据源是数据表。

我希望网格视图中的最后一列包含超链接列表。我无法弄清楚如何存储或显示这些数据

private void retrieveGroups()
{
    // UserTab is a DataTable
    // UserGrid is a GridView
    UserTab.Columns.Add("LoginName", typeof(string));
    UserTab.Columns.Add("DisplayName", typeof(string));
    UserTab.Columns.Add("Kind", typeof(string));
    UserTab.Columns.Add("Count", typeof(string));
    UserTab.Columns.Add("Managers", typeof(string));
    UserGrid.DataSource = UserTab;

    SqlCommand cmd = FmaDb.makeCmd(FmaDb.SubDB.FMA_CUSTOMER, "fetchGroupIds", CommandType.StoredProcedure,
        delegate(SqlCommand inCmd) { inCmd.Parameters.Add("@siteid", SqlDbType.Int); });
    List<int> groupIds = new List<int>();
    FmaDb.runReadCmd(cmd, delegate(SqlCommand inCmd) { inCmd.Parameters["@siteid"].Value = int.Parse(LFList.SelectedItem.Value); }, null,
        delegate(SqlDataReader qrdr) { groupIds.Add(FmaDb.getDbInt(qrdr, 0)); });

    UserGrid.Visible = true;
    HyperLinkField hf = new HyperLinkField();
    BoundField bf = new BoundField();
    hf.HeaderText = "Login";
    hf.DataTextField = "LoginName";
    hf.DataNavigateUrlFields = new String[1] { "login" };
    hf.DataNavigateUrlFormatString = "~/fausage.aspx?cn=login&lg={0}&ad=" + ad + "&as=" + aStatus;
    UserGrid.Columns.Add(hf);

    bf = new BoundField();
    bf.HeaderText = "Name";
    bf.DataField = "DisplayName";
    UserGrid.Columns.Add(bf);
    bf = new BoundField();
    bf.HeaderText = "Type";
    bf.DataField = "Kind";
    UserGrid.Columns.Add(bf);

    bf = new BoundField();
    bf.HeaderText = "# Members";
    bf.DataField = "Count";
    UserGrid.Columns.Add(bf);

    bf = new BoundField();
    bf.HeaderText = "Managers";
    bf.DataField = "Managers";
    UserGrid.Columns.Add(bf);

    foreach (int gId in groupIds)
    {
        Advisor advGroup = new Advisor(gId);
        List<HyperLink> linkList = new List<HyperLink>();
        advGroup.fetch();

        if ((advGroup.Kind == AdvisorKind.Branch) || (advGroup.Kind == AdvisorKind.Team))
        {
            List<AdvisorMembership> members = advGroup.MyMembers(null, false);

           if (advGroup.Kind == AdvisorKind.Branch)
           {
                List<AdvisorMembership> mgrs = advGroup.MyMembers(null, true);
                HyperLink link;
                foreach (AdvisorMembership m in mgrs)
                {
                    if (m.MemberCanLoginAsContainer)
                    {
                        link = new HyperLink();
                        link.Text = m.Member.LoginName;
                        link.NavigateUrl = "~/fausage.aspx?cn=login&lg=" + m.Member.LoginName + "&ad=" + ad + "&as=" + aStatus;
                        link.Target = "blank";
                        linkList.Add(link);
                    }
                }
             }
             UserTab.Rows.Add(advGroup.LoginName, advGroup.DisplayName, advGroup.Kind.ToString(), members.Count.ToString(), linkList);
             }
             ViewState["DataTable"] = UserTab;
           }
        }
    }

}

0 个答案:

没有答案