网格视图添加列 [英] Grid view add column
本文介绍了网格视图添加列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 GridView
和一个 DataTable
;网格视图的来源是数据表。
我想在网格视图中添加新列;此列将我的页面重定向到expamle的特殊页面: resualt.aspx?module = id
我怎样才能制作这个专栏?
记住:我的griadview在运行时获取数据源!!!
Hi,
I have a GridView
and a DataTable
; the source of grid view is data table.
I would like to add new Column to the grid view; this column redirect my page to special page for expamle: resualt.aspx?module=id
How can I make this column?
remeber : My griadview get datasource in run time !!!
DataTable dt = db.Select(quarry, CommandType.Text);
dt.Columns.Add("more" typeof(string));
foreach (DataRow ro in dt.Rows)
{
ro["more"] = "<a href='~/resualt.aspx?module='"+ro[id].toStrimg()+"> More Info </a>";
}
GridView1.DataSource = dt;// Get Data source in run Time
GridView1.DataBind();
我知道也许这不是正常的方式;但我想这样做。
I know maybe it''s not a normal way; but I would like to do it this way.
推荐答案
您可以在Gridview中添加模板字段,如:
Hi,
You can add a template field in Gridview like:
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" CommandArgument='<%# Eval("Id") %>'
OnClick="Redirect_Click" Text="Edit" CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
</asp:TemplateField>
</Columns>
并在代码后面添加以下代码:< br $> b $ b
and add below code in code behind:
protected void ShowModal(object sender, EventArgs e)
{
LinkButton linkButton = (LinkButton)sender;
string id = linkButton.CommandArgument;
Response.Redirect("resualt.aspx?module="+id);
}
谢谢。
Thank You.
嗨..请参阅以下链接
http://stackoverflow.com/questions/1486062/how-do-i-add-a-column-with-buttons-in-to-a-gridview- in-asp-net [ ^ ]
http://stackoverflow.com/questions/8859279/how-to-add-link-in-gridview-asp -net [ ^ ]
HTTP ://www.asp.net/web-forms/tutorials/data-access/custom-button-actions/adding-and-responding-to-buttons-to-a-gridview-vb [ ^ ]
Hi.. Refer to the below links
http://stackoverflow.com/questions/1486062/how-do-i-add-a-column-with-buttons-in-to-a-gridview-in-asp-net[^]
http://stackoverflow.com/questions/8859279/how-to-add-link-in-gridview-asp-net[^]
http://www.asp.net/web-forms/tutorials/data-access/custom-button-actions/adding-and-responding-to-buttons-to-a-gridview-vb[^]
这篇关于网格视图添加列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文