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

  • Home
  • SEARCH
  • 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 8578273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:21:00+00:00 2026-06-11T20:21:00+00:00

First, I am selecting all records on page-load like this: OleDbCommand objCmd = new

  • 0

First, I am selecting all records on page-load like this:

OleDbCommand objCmd = new OleDbCommand("SELECT * FROM MyTable", mycon);
objCmd.CommandType = CommandType.Text;
DataTable dtTemp = new DataTable();
OleDbDataReader rd = objCommand.ExecuteReader();
if (rd.HasRows)
{
    dtTemp.Load(rd);
    gvTemp.DataSource = dtTemp;
    gvTemp.DataBind();
}

In GridView(gvTemp), I am passing MemID in CommandArgument like this:

<asp:TemplateField HeaderText="Action" ItemStyle-Width="80px">
    <ItemTemplate>
        <asp:LinkButton ID="lbtnStart" runat="server" CommandArgument='<%# Eval("MemID") %>' CommandName="Start">Start</asp:LinkButton>
    </ItemTemplate>
</asp:TemplateField>

So when I click on Start, gvTemp_RowCommand is fired and I want to get CommandArgument (MemID). So I am doing this to achieve it:

protected void gvTemp_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Start")
    {
        Response.Redirect("AddMem.aspx?MemID=" + e.CommandArgument.ToString());
    }
}

This work fine. But problem is here.
When user search for a particular record, I reload gvTemp like this:

OleDbCommand objCmd = new OleDbCommand("SELECT * FROM MyTable WHERE MemID = ?", mycon);
objCmd.Parameters.Add(myParam); 
objCmd.CommandType = CommandType.Text;
DataTable dtTemp = new DataTable();
OleDbDataReader rd = objCommand.ExecuteReader();
if (rd.HasRows)
{
    dtTemp.Load(rd);
    gvTemp.DataSource = dtTemp;
    gvTemp.DataBind();
}

Executing this query, I am getting only one record. And when I click on Start, gvTemp_RowCommand is fired. But I am getting e.CommandArgument of old DataSource. (i.e. The top 1 MemID of SELECT * FROM MyTable). So before binding actual DataSource I clear the GridView like this:

gvTemp.DataSource = null;
gvTemp.DataBind();
gvTemp.DataSource = dtTemp;
gvTemp.DataBind();

But still I am getting e.CommandArgument of old DataSource. So what am I missing? Or is there any alternative method to achieve the same?

  • 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-06-11T20:21:01+00:00Added an answer on June 11, 2026 at 8:21 pm

    On every button click a postback occurs and the page load event occurs so in your case this might be the reason why previous data source is being loaded. so you must check IsPostBack condition.

    Try something like this:

    if(!IsPostBack)
       //Your code or method for selecting all records.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, this isn't for a keylogger, it's for an input in a
first take a look on this picture from localScope app : i have 2
I was wondering if there is a way to do something like selecting all
I have two tables. I try to select some records from one of them.
I have a problem with selecting not first selector using attributeContains jQuery('div[id*=abc]:not(:first)').hide();
In my project i want to first view country in combobox then selecting country
first of all some details: I configured security as below in web.xml view plaincopy
First off, I'm coming (back) to Java from C#, so apologies if my terminology
First i selected images from photo library to ALAsset Library and after that i
i have cursor which selects records from my CarProfile table and use custom adapter

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.