使用SqlDataSource.insert将数据插入到sortite网格视图中,如何显示新行以进行编辑? [英] Insert Data with SqlDataSource.insert in a sortet gridview, how show new row for edit?
本文介绍了使用SqlDataSource.insert将数据插入到sortite网格视图中,如何显示新行以进行编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有带有页面的GridView,该页面连接到SqlDataSource.
现在,我使用SqlDataSource.Inserte()将新数据插入数据库.
这样就可以了.
问题是,gridview是sortet,新数据在第x行y而不是在第一行或最后一行.
如何在Gridview中选择/聚焦新数据,以便用户可以查看和编辑新数据
I have GridView with pages which is connect to a SqlDataSource.
Now I insert a new Data with SqlDataSource.Inserte() to the DB.
So it''s work fine.
The problem is, that the gridview is sortet and the new Data is on Page x Line y not at the first or last Row.
How can I select/focus the new Data in the Gridview so the user can see and edit it
推荐答案
现在我找到了Answere:
在insertSting中:"insert ...)RETURNING ID INTO:NewID"
在插入调用中:
Now I found the Answere:
in the insertSting: " insert...) RETURNING ID INTO :NewID"
in the insert call:
protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
object newId = e.Command.Parameters["NewID"].Value;
if (newId != null)
{
ViewState["NewId"] = Convert.ToString(newId);
}
GridView1.DataBind();
}
现在结束了
and now the end
protected void Page_PreRender(object sender, EventArgs e)
{
string newIdLast = string.Empty;
if (ViewState["NewId"] != null)
{
String newId = (String)ViewState["NewId"];
newIdLast = newId.ToString();
int rowCnt = 0;
GridView1.PageIndex = 0;
int MAxpage = GridView1.PageCount;
for (int i = 0; i < MAxpage; i++)
{
GridView1.PageIndex = i;
GridView1.DataBind();
rowCnt = 0;
foreach (GridViewRow row in GridView1.Rows)
{
string newIdText = row.Cells[1].Text;
if (newIdText.Equals(newIdLast))
{
GridView1.PageIndex = i;
GridView1.SelectedIndex = rowCnt;
i = 9999;
break;
}
rowCnt++;
}
}
ViewState["NewId"] = null;
}
}
不好,但是仍然可以. :-O
It''s not fine, but still works. :-O
现在,我遇到了一个新问题.
函数Page_PreRender(object sender,EventArgs e)...
要变慢,我该怎么做才能加快速度?
Now, I have a new problem.
The Function Page_PreRender(object sender, EventArgs e)...
is to slow, what can i do to speed it up?
您好,
可以帮我吗?
请:((
Hello,
can some help me?
Please :((
这篇关于使用SqlDataSource.insert将数据插入到sortite网格视图中,如何显示新行以进行编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文