在我的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;
答案 0 :(得分:2)
:make AllowSorting="false"
它将自动插入最后一行