Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 !!!

C#
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.
Posted
Updated 27-Feb-13 21:59pm
v4
Comments
Shanu2rick 28-Feb-13 5:01am    
what happened when you tried the above code?

Hi,
You can add a template field in Gridview like:

XML
<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>


and add below code in code behind:

C#
protected void ShowModal(object sender, EventArgs e)
        {
            LinkButton linkButton = (LinkButton)sender;
            string id = linkButton.CommandArgument;
            Response.Redirect("resualt.aspx?module="+id);
}


Thank You.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900