Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 11-Feb-13 0:37am
v2

Why you fetch your texbox's value from session?
Fetch directly from the textbox.
No need to store textbox's value in session.
 
Share this answer
 
Comments
devausha 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....
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.
 
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