I am adding multiple rows in gridview. Now i want that latest added row display on top in gridview?
private void insertbalgv()
{
if
(txtdno.Text != "")
{
Response.Write("<script language='javascript'>alert('Bale Already Dispatch');</script>");
}
else if
(txtqty.Text == "")
{
Response.Write("<script language='javascript'>alert('Please Input QTY');</script>");
}
else
{
if (DDLitem.SelectedItem != null)
{
int codeitem = Convert.ToInt32(DDLitem.SelectedItem.Value.ToString());
string Descriptionitem = DDLitem.SelectedItem.Text.ToString();
DataTable dtgridview = ViewState["dt"] as DataTable;
DataRow dr2 = dtgridview.NewRow();
bool ifExist = false;
foreach (DataRow dr in dtgridview.Rows)
{
if (dr["BID"].ToString() == txtsearcbn.Text.Trim())
{
ifExist = true;
break;
}
}
if (!ifExist)
{
dr2["Index"] = dtgridview.Rows.Count + 1;
dr2["BID"] = txtsearcbn.Text.Trim();
dr2["Codeitem"] = codeitem;
dr2["Descriptionitem"] = Descriptionitem;
dr2["QTY"] = txtqty.Text;
dr2["BWeight"] = txtwht.Text;
dtgridview.Rows.Add(dr2);
ViewState["dt"] = dtgridview;
GVbal.DataSource = dtgridview;
GVbal.DataBind();
BindSummaryGrid(dtgridview);
lb.Text = "";
}
else
{
// Response.Write("<script language='javascript'>alert('Bale Already Added');</script>");
lb.Text = "Bale Already Added";
}
clear();
}
}
}