14 列のグリッドビューが 1 つあります。そのうちのProductUID
1 つは非表示で、もう 1 つはテキスト ボックスAutoCompleteExtender
です。
このテキストボックスを使用して製品名を選択しました。FillGridView
その選択された製品の関数塗りつぶしグリッドビュー。しかし、問題は、新しい製品を追加するときに最初にAddNewRow()
関数を呼び出すことです。グリッドビューに新しい行を追加し、関数を呼び出しましfillgridview()
た。選択した製品の詳細ですべての列を埋めました。
その後、次の行に別の新しい製品を追加すると、前の行が失われ、最初のセルデータのみが失われ、他の列は保存されたままになります。
私のソースコードの問題は何ですか?
私を助けてください!
private void AddNewRow()
{
try
{
int rowIndex = 0;
if (Session["CurrentTable"] != null)
{
DataTable dtCurrentTable = (DataTable)Session["CurrentTable"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
{
string boundfield0 = gvCounterSale.Rows[rowIndex].Cells[(int)CounterSaleColumnIndex.ProductID].Text;
TextBox TextBoxItemName =
(TextBox)gvCounterSale.Rows[rowIndex].Cells[(int)CounterSaleColumnIndex.ItemName].FindControl("item_txtBox");
string boundfield1 = gvCounterSale.Rows[rowIndex].Cells[(int)CounterSaleColumnIndex.Company].Text;
string boundfield2 = gvCounterSale.Rows[rowIndex].Cells[(int)CounterSaleColumnIndex.Packing].Text;
string boundfield3 = gvCounterSale.Rows[rowIndex].Cells[(int)CounterSaleColumnIndex.Unit].Text;
string boundfield4 = gvCounterSale.Rows[rowIndex].Cells[(int)CounterSaleColumnIndex.Expiry].Text;
string boundfield5 = gvCounterSale.Rows[rowIndex].Cells[(int)CounterSaleColumnIndex.MRP].Text;
string boundfield6 = gvCounterSale.Rows[rowIndex].Cells[(int)CounterSaleColumnIndex.ShelfNo].Text;
string boundfield7 = gvCounterSale.Rows[rowIndex].Cells[(int)CounterSaleColumnIndex.BatchNo].Text;
string boundfield8 = gvCounterSale.Rows[rowIndex].Cells[(int)CounterSaleColumnIndex.Stock].Text;
TextBox TextBoxQuantity =
(TextBox)gvCounterSale.Rows[rowIndex].Cells[(int)CounterSaleColumnIndex.Quantity].FindControl("qty_txtBox");
string boundfield9 = gvCounterSale.Rows[rowIndex].Cells[(int)CounterSaleColumnIndex.Amount].Text;
Button ButtonRemove =
(Button)gvCounterSale.Rows[rowIndex].Cells[(int)CounterSaleColumnIndex.Button].FindControl("btnRemove");
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["RowNumber"] = i + 1;
dtCurrentTable.Rows[i - 1]["ProductID"] = boundfield0;
dtCurrentTable.Rows[i - 1]["Col1"] = TextBoxItemName.Text;
dtCurrentTable.Rows[i - 1]["Company"] = boundfield1;
dtCurrentTable.Rows[i - 1]["Packing"] = boundfield2;
dtCurrentTable.Rows[i - 1]["Unit"] = boundfield3;
dtCurrentTable.Rows[i - 1]["Expiry"] = boundfield4;
dtCurrentTable.Rows[i - 1]["Pur_Rate"] = boundfield5;
dtCurrentTable.Rows[i - 1]["Shelf_No"] = boundfield6;
dtCurrentTable.Rows[i - 1]["Batch_No"] = boundfield7;
dtCurrentTable.Rows[i - 1]["Stock"] = boundfield8;
dtCurrentTable.Rows[i - 1]["Col10"] = TextBoxQuantity.Text;
dtCurrentTable.Rows[i - 1]["Amount"] = boundfield9;
dtCurrentTable.Rows[i - 1]["Col11"] = ButtonRemove;
rowIndex++;
}
dtCurrentTable.Rows.Add(drCurrentRow);
Session["CurrentTable"] = dtCurrentTable;
gvCounterSale.DataSource = dtCurrentTable;
gvCounterSale.DataBind();
}
}
else
{
Response.Write("Session is null");
}
SetPreviousData();
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(Page, this.GetType(), "hi", "alert('Error Occured');", true);
}
}
private void FillGridView()
{
try
{
Guid puid = new Guid();
puid = System.Guid.ParseExact(hdnProductId.Value, "D");
int rowIndex = gvCounterSale.Rows.Count - 1;
DataTable dtCurrentTable = (DataTable)Session["CurrentTable"];
string connStr = ConfigurationManager.ConnectionStrings["pharmacy_ConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
con.Open();
SqlDataReader dr = null;
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i < gvCounterSale.Rows.Count; i++)
{
if (rowIndex != gvCounterSale.Rows.Count)
{
StringBuilder sb = new StringBuilder();
sb.Append(" SELECT STOCK.PRODUCT_ID, STOCK.BATCH_NO, STOCK.COMPANY_NAME, STOCK.EXPIRY, STOCK.PUR_RATE, STOCK.MRP, STOCK.SHELF_NO, ");
sb.Append(" STOCK.OPENING_STOCK, PRODUCT.PRODUCT_ID, PRODUCT.UNIT, PRODUCT.PACKING ");
sb.Append(" FROM STOCK INNER JOIN PRODUCT ");
sb.Append(" ON STOCK.PRODUCT_ID=PRODUCT.PRODUCT_ID WHERE PRODUCT.PRODUCT_ID = '" + puid + "'GROUP BY STOCK.PRODUCT_ID, STOCK.BATCH_NO, STOCK.COMPANY_NAME, ");
sb.Append("STOCK.EXPIRY, STOCK.PUR_RATE, STOCK.MRP, STOCK.SHELF_NO, STOCK.OPENING_STOCK, PRODUCT.PRODUCT_ID, PRODUCT.UNIT, PRODUCT.PACKING ");
SqlCommand cmdid = new SqlCommand(sb.ToString(), con);
dr = cmdid.ExecuteReader();
while (dr.Read())
{
gvCounterSale.Rows[rowIndex - 1].Cells[(int)CounterSaleColumnIndex.ProductID].Text = puid.ToString();
gvCounterSale.Rows[rowIndex - 1].Cells[(int)CounterSaleColumnIndex.Packing].Text = dr["PACKING"].ToString();
gvCounterSale.Rows[rowIndex - 1].Cells[(int)CounterSaleColumnIndex.Unit].Text = dr["UNIT"].ToString();
DateTime dt = Convert.ToDateTime(dr["EXPIRY"].ToString());
gvCounterSale.Rows[rowIndex - 1].Cells[(int)CounterSaleColumnIndex.Company].Text = dr["COMPANY_NAME"].ToString();
gvCounterSale.Rows[rowIndex - 1].Cells[(int)CounterSaleColumnIndex.Expiry].Text = dt.ToShortDateString();
gvCounterSale.Rows[rowIndex - 1].Cells[(int)CounterSaleColumnIndex.MRP].Text = dr["MRP"].ToString();
gvCounterSale.Rows[rowIndex - 1].Cells[(int)CounterSaleColumnIndex.ShelfNo].Text = dr["SHELF_NO"].ToString();
gvCounterSale.Rows[rowIndex - 1].Cells[(int)CounterSaleColumnIndex.BatchNo].Text = dr["BATCH_NO"].ToString();
gvCounterSale.Rows[rowIndex - 1].Cells[(int)CounterSaleColumnIndex.Stock].Text = dr["OPENING_STOCK"].ToString();
}
//rowIndex++;
dr.Close();
}
}
con.Close();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(Page, this.GetType(), "hi", "alert('Error Occured');", true);
}
}