1

使用网格视图从后面的代码绑定它:

我想将一个特定的列数据绑定到一个超链接中,所以当它点击它应该进行下载。

怎么做 ?

下面是我的代码:

for (int i = 0; i <= tbl.Columns.Count - 1; i++) 
{
    Telerik.Web.UI.GridBoundColumn boundfield = new Telerik.Web.UI.GridBoundColumn();

    if (tbl.Columns[i].ColumnName.ToString() == "Row") 
    {

        LinkButton lkbtn = new LinkButton();
        lkbtn.CommandName = i;
        lkbtn.CommandArgument = "dwnld";
        lkbtn.Font.Underline = true;
        lkbtn.Text = tbl.Columns(i).ColumnName.ToString();

        boundfield.DataField = tbl.Columns(i).ColumnName.ToString()
        boundfield.HeaderText = tbl.Columns(i).ColumnName.ToString();

        GridView2.MasterTableView.Columns.Add(boundfield);

    }
}
4

1 回答 1

0

为什么不使用带有链接按钮的网格模板列。

<telerik:GridTemplateColumn>
       <ItemTemplate>
          <asp:LinkButton ID="btnDownload" OnClick="btnDownload_Click" runat="server">Download Something</asp:LinkButton>
        </ItemTemplate>
   </telerik:GridTemplateColumn>


protected void btnDownload_Click(object sender, EventArgs e)
{
  LinkButton lbBtn = sender as LinkButton;
  GridDataItem item = (GridDataItem)(sender as LinkButton).NamingContainer;
  // Use item to get other details
...
...
}
于 2015-07-24T06:54:02.493 回答