Reputation: 349
In my gridview I have a primary key column. The newly inserted rows are inserting according to the descending order of this primary key defaultly. How can I avoid this? And I want to display newly inserted records to the last row of gridview. My code is here
SqlConnection con = obj.getcon();
con.Open();
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(select_string, con);
adapter.Fill(ds);
GridView2.DataSource = ds;
GridView2.DataBind();
con.Close();
foreach (GridViewRow grv in GridView2.Rows)
{
if (grv.RowType == DataControlRowType.DataRow)
{
if (grv.RowIndex > lastRowIndex)
{
lastRowIndex = grv.RowIndex;
}
}
}
lastRowIndex = GridView2.Rows.Count - 1;
GridView2.Rows[lastRowIndex].BackColor = System.Drawing.Color.LightGoldenrodYellow;
Upvotes: 0
Views: 624
Reputation: 1833
in your design: make AllowSorting="false"
and it will insert at the last row automatically
Upvotes: 2