在我的 gridview 中,我有一个主键列。新插入的行默认按照该主键的降序插入。我怎样才能避免这种情况?我想将新插入的记录显示到gridview的最后一行。我的代码在这里
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;