我有这段代码从我的数据库获取数据到Gridview:
public void mainSelect(DataGridView gvMain)
{
string sSQL = " SELECT" +
" tbMain.id, tbBrand.name AS brand, tbModel.name AS model, tbMain.name, tbType.name AS type, tbClub.name AS club, tbMain.serial, tbMain.porder, tbMain.link, tbUser.name AS lastEditBy, tbMain.lastEditDate" +
" FROM" +
" tbMain, tbBrand, tbModel, tbType, tbClub, tbUser" +
" WHERE" +
" tbBrand.id = tbMain.brand" +
" AND" +
" tbModel.id = tbMain.model" +
" AND" +
" tbType.id = tbMain.type" +
" AND" +
" tbClub.id = tbMain.club" +
" AND" +
" tbUser.id = tbMain.lastEditBy" +
" ORDER BY " +
" club ASC";
sqlConnect connect = new sqlConnect();
DataTable dt = new DataTable();
dt = connect.getBD(sSQL);
gvMain.DataSource = dt;
gvMain.Columns[0].HeaderText = "ID";
gvMain.Columns[1].HeaderText = "Brand";
gvMain.Columns[2].HeaderText = "Model";
gvMain.Columns[3].HeaderText = "Computer Name";
gvMain.Columns[4].HeaderText = "Type";
gvMain.Columns[5].HeaderText = "Site";
gvMain.Columns[6].HeaderText = "Serial Number";
gvMain.Columns[7].HeaderText = "Purchase Order";
gvMain.Columns[8].HeaderText = "Invoice Link";
gvMain.Columns[9].HeaderText = "Last Edit By";
gvMain.Columns[10].HeaderText = "Last Edit Date";
它工作正常,我现在需要的是将第8列(发票链接)设置为链接字段,以便我可以单击并打开它。
我该怎么做到这一点?感谢
答案 0 :(得分:0)
尝试使用DataGridViewLinkColumn
DataGridViewLinkColumn link = new DataGridViewLinkColumn();
link.DataPropertyName = "InvoiceLink";
link.Name = "Invoice Link";
dataGridView1.Columns.Add(link);
绑定网格后将其添加到网格中
您可能需要将AutoGenerateColumns
设置为false
答案 1 :(得分:0)
在Gridview中使用模板字段:
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Bind("LeadID") + Request.QueryString("type") %>'
Text=""></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>