0

I want to add a link button in grid view dynamically, that button should keep parameter and when user click the button it has to go to respective page where i map

For ex: If button text is "View more" when user clicks the button,button will pass 'id' value, it will move to Details.aspx?id=10 and on that page, it will show the data by retrieve from database using that id value.

I know how to retrieve data from database. But i don't know hot add link button with parameter.

Here this is my code

protected void Page_Load(object sender, EventArgs e)
    {
        // data load to grid view
        loadDataTable();

    }

    private void loadDataTable()
    {
        DataSet ds = new DataSet();
        DataTable dt;
        DataRow dr;

        DataColumn date;
        DataColumn designation;
        DataColumn experience;
        DataColumn location;
        DataColumn nationality;
        DataColumn details;

        dt = new DataTable();

        date = new DataColumn("Date");
        designation = new DataColumn("Designation");
        experience = new DataColumn("Experience");
        location = new DataColumn("Location");
        nationality = new DataColumn("Nationality");
        details = new DataColumn("Details");

        dt.Columns.Add(date);
        dt.Columns.Add(designation);
        dt.Columns.Add(experience);
        dt.Columns.Add(location);
        dt.Columns.Add(nationality);
        dt.Columns.Add(details);

        dr = dt.NewRow();

        dr["Date"] = "10/2/2016";
        dr["Designation"] = "Asp.net";
        dr["Experience"] = "5";
        dr["Location"] = "Jeddah";
        dr["Nationality"] = "Indian";
        dr["Detais"] = "";   // ADD LINK BUTTON 

        dt.Rows.Add(dr);

        ds.Tables.Add(dt);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();


    }

asp.net code

<div class="row">
                <div class="col-sm-12 col-md-12 col-lg-12">
                    <asp:GridView ID="GridView1" runat="server"></asp:GridView>
                </div>
            </div>

I want to add link button in Details header.

please help me. I am new to gridview and asp.net

1 Answer 1

2

how about adding an anchor?

dr["Detais"] = "<a href='Details.aspx?id="+ dr["id"].ToString() + "' target='_blank'>View Details</a>";

I'm not sure about the id field but this will work

EDIT

Change the Details column into a Literal column with something like this:

<asp:TemplateField headertext="Details">
   <ItemTemplate>
      <asp:Literal id="Literal1" runat="server" text='<%# Eval ("Details") %>'></asp:Literal>
   </ItemTemplate>
</asp:TemplateField>
Sign up to request clarification or add additional context in comments.

1 Comment

That is considering as a string. So it is printing all your code which inside " "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.