Click here to Skip to main content
11,706,007 members (51,169 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
In my project I m using barcode for fetch book from database. I m using usb barcode reader for read the barcode. I get the barcode to textbox. I give the following coding for bind the gridview in textchanged event. It is working fine. First time I show the barcode reader the Function is calling two times. And then Second time I show the another barcode the datatable has correct value. But the gridview show the datas for first time execution.

My codings are following

private void Add_IssueDet()
  {
 
      try
      {
          string barcode_id = (string)Session["Pin2Value"];
          //string barcode_id = "0005427036";
          if (barcode_id != "")
          {
              DataTable dtIssueDet;
              if (Session["dtIssueDet"] == null)
                  PrepareTable();
              dtIssueDet = (DataTable)Session["dtIssueDet"];
 

              DataRow drIssueDet = dtIssueDet.NewRow();
              DataTable Issueempty = new DataTable();
              DataTable dtbookdetails = new DataTable();
 
              dtbookdetails = objDB.Get_BooksDetails_By_Barcode(barcode_id);
              //  bool isedit = (bool)ViewState["IsEdit"];
              bool isedit = false;
              if (isedit != true)
              {
                  drIssueDet["IssueDetailsId"] = dtIssueDet.Rows.Count;
                  drIssueDet["IssueId"] = objDB.GetMaxIDForIssue();
              }
              else
              {
                  drIssueDet["IssueDetailsId"] = 0;
                  if (dtIssueDet.Rows.Count == 0)
                  {
                      drIssueDet["IssueId"] = ViewState["LibIssueID"];
                  }
                  else
                  {
                      drIssueDet["IssueId"] = Convert.ToInt32(dtIssueDet.Rows[0]["IssueId"]);
                  }
              }
              if (dtbookdetails.Rows.Count > 0)
              {
                  drIssueDet["BookCategoryName"] = dtbookdetails.Rows[0]["CategoryName"].ToString();
                  drIssueDet["CategoryId"] = dtbookdetails.Rows[0]["CategoryID"].ToString();
                  drIssueDet["TitleName"] = dtbookdetails.Rows[0]["Title"].ToString();
                  drIssueDet["StockID"] = dtbookdetails.Rows[0]["Book_ID"].ToString();
                  //SessionConfig.Current.LibQuantity = objDA.GetQty(SessionConfig.Current.LibStockID);
                  drIssueDet["ReservedCode"] = "-";
                  drIssueDet["ReservedID"] = 0;
                  drIssueDet["ReservedDate"] = "-";
                  drIssueDet["Quantity"] = 1;
                  ViewState["LibQuantity"] = Convert.ToInt32(dtbookdetails.Rows[0]["stock"]);
                  drIssueDet["Description"] = "";
                  dtIssueDet.Rows.Add(drIssueDet);
                  Session["dtIssueDet"] = dtIssueDet;
                  //Session["Pin2Value"] = null;
                  grvIssueDet.DataSource = dtIssueDet;
                  grvIssueDet.DataBind();
 

 
                  GridView1.DataSource = dtIssueDet;
                  GridView1.DataBind();
 
              }
          }
      }
 
      catch (Exception ex)
      {
          objLog.ErrorLog("LibIssueDetails", "Add_IssueDet", ex.Message.ToString(), KansasErrorLog.ErrorLogMethods.TextFile, "KansasDEMS");
      }
  }
  protected void txt_barcode_id_TextChanged(object sender, EventArgs e)
{
      Session["Pin2Value"] = txt_barcode_id.Text;
 
      Add_IssueDet();
      //txt_barcode_id.Text = "";
  }

I didn't know what is the problem. When I show the barcode first time, the code is execute two times, it bind the same datas two times and show to the gridview. Second time I show the barcode, It fetch the datas and bind the datatable, but the gridview displays only first time execution datas. Pls help me.....for this issue

And then I check, The textbox autopostback is false, It execute one time. the datatable has get the value correctly. But the gridview is show only first row of the datatable, actually that datatable has three rows.
Posted 11-Feb-13 0:32am
devausha1.4K
Edited 11-Feb-13 0:37am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Why you fetch your texbox's value from session?
Fetch directly from the textbox.
No need to store textbox's value in session.
  Permalink  
Comments
devausha at 11-Feb-13 23:31pm
   
I found the problem, why it is? Because I m using calendar Extendar in Textbox with in gridview. If I remove the calendar extender, it Binds and view correctly. But I must used calendar extendar to select date. Please help me....
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I found the problem, why it is? Because I m using calendar Extendar in Textbox with in gridview. If I remove the calendar extender, it Binds and view correctly.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 142
1 Sergey Alexandrovich Kryukov 137
2 ppolymorphe 71
3 Mika Wendelius 70
4 chainerlt 70
0 OriginalGriff 9,050
1 Sergey Alexandrovich Kryukov 8,417
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,636


Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 12 Aug 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100