Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7658983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:16:21+00:00 2026-05-31T13:16:21+00:00

now i am very confused with how to create gridview with the following structure

  • 0

now i am very confused with how to create gridview with the following structure and criteria:

note: the gridview will take data from different tables

columns:
1. IDcol the unique value and it will be from tableA(as text)
2. Date it will from also tableA(as text)
3. link1 it will be hyperlink to another page and the parameter for the url will be ‘IDcol’ column value but the text displayed will changed if this record is exists in tableB with the same ‘IDcol’ the dispalyed will be “view/edit” if not exists it will be “Add New”

database structure:

tableA:

IDcol as (primary key),
Date

tableB:

ID,
IDcol as (foreign key from tableA).
other fields

so i need populate the gridview using loop because i have to check for each row and use some conditions

sorry if my way of description is not clear but i am really confused


My code for deleting part:

        <asp:LinkButton ID="DeleteLink" runat="server" Text="Delete"     CommandName="Delete"></asp:LinkButton>
        </ItemTemplate>
        <ItemStyle Width="100px" />
        </asp:TemplateField>


 DeleteCommand="DELETE VisitsInfo WHERE ID=@VID">


 <DeleteParameters>
                <asp:Parameter Name="VID" Type="Int64" />
            </DeleteParameters>

in code behind :

 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

            int VID = int.Parse(GridView1.DataKeys[0].Value.ToString());
            SqlDataSourceVisits.DeleteParameters[0].DefaultValue = VID.ToString();

    }

when i click on delete link to delete row it works but when refresh the page its delete another row without click the delete link so why that happened??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:16:22+00:00Added an answer on May 31, 2026 at 1:16 pm

    No matter how many tables you are using to display data in a Gridview, the best and more flexible approach is to use OnRowDataBound.

    //do some database queries to return the appropriate value
    DataTable dt = new DataTable();
    private void Bind()
    {
        //set up the dt with all the required data from single or multiple tables
    }
    
    //Then in the page Load method, call the above Bind method
    protected void Page_Load(object sender, EventArgs e)
    {
         if (!IsPostBack)
         {
              Bind();
         }
    }
    
    //then do something like the following 
    int idx = 0;    
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //do some database queries to return the appropriate value, then do something like the following
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Text = dt.Rows[idx][0];
            e.Row.Cells[1].Text = dt.Rows[idx][1];
            //or maybe
            ((TextBox)e.Row.Cells[0].FindControl("textBox1")).Text = dt.Rows[idx][0];
            ((Label)e.Row.Cells[1].FindControl("label2")).Text = dt.Rows[idx][1];
            ((CheckBox)e.Row.Cells[1].FindControl("chkbx1")).Selected = (bool)dt.Rows[idx][2]; 
    
            idx++;
        }
    }
    

    And as Pranay said, you may wish to use Linq and join to get the required data from all tables, though, you can still get them in any other way you feel comfortable with

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I'm now very confused. After my last question had several people comment about
I'm finally able to get an Access Token, now I'm very confused as how
I have heard that DateTime.Now is very expensive call (from here ) Is GETDATE()
Today i was told to create tree data structure with the below class, public
Very confused over this. I've just started learning about pointers and have now decided
Im getting very confused with indexes in MySQL. I have two tables: TableA1 and
I have been studying python for quite sometime now and very recently I decided
I am very desperate now... I have project in Visual C++ 2010 using Qt
I've been programming in c++ for a bit now and Im very familiar with
Introduction: Now I know this question could be very broad and it would be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.