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"];
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 = 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();
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;
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();
}
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.