1

表结构如下:

id int identity
firstname varchar(100) 
lastname varchar(100)

我有一个在 profile.aspx 页面上显示/插入/更新名字姓氏的详细信息视图控件。

如果客户以查询字符串中的 id 登陆此页面,那么我希望它通过 sqldatasource 将该记录加载到详细信息视图中并启用编辑按钮。

如果客户在查询字符串中没有 id 的情况下登陆此页面,那么我希望它通过 sqldatasource 将名字/姓氏记录的空白显示到详细信息视图中,并启用插入按钮。

我怎么做到这一点???

请帮忙...

4

3 回答 3

1

在您的 Page_Load 中设置一个条件

Page_Load
{

check query string and find empID

If (empID != null)
{

detailsView1.ChangeMode(DetailsViewMode.Edit);
}
else
{


detailsView1.ChangeMode(DetailsViewMode.Insert);
}

}
于 2009-04-14T17:56:38.060 回答
1

如果传入了 ID,请使用此方法将 DetailsView 弹出到编辑模式:

    Dim theID As Int32 = Request.QueryString("id")
    If Not theID Is Nothing Then
        SqlDataSource.SelectParameters("THE_ID").DefaultValue = theID
        SqlDataSource.DataBind()
        DetailsView.ChangeMode(DetailsViewMode.Edit)
    End If  

只需对“没有传入 ID”的情况进行一些额外的调整。

于 2009-03-05T05:38:57.170 回答
0

阅读此使用 ASP.NET 2.0 SqlDataSource 更新数据库

使用以下代码检查是否有传入的 id 是否使用他的数据填充字段。

int EmpID = 0;

if (Request.Querystring.Get("EmpID") != null) 
{ 
    id = Page.Request.QueryString["EmpID"];
    //load your values
}
于 2009-03-05T05:02:01.440 回答