0
我有一個從sql表記錄的gridview。我在3層架構中設置了網頁,當我選擇從gridview編輯特定記錄時,它給了我一個formview,裏面填充了我在gridview中選擇的記錄的詳細信息。當我在更改後單擊更新鏈接按鈕在formview上的一些細節,gridview顯示與選定的行的空白記錄。我需要在gridview這一行有數據。在gridview上編輯模式顯示要用空值編輯的記錄
請幫忙。
我的代碼在後面。
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGrid();
fvProfiles.Visible = false;
}
}
protected void BindGrid()
{
gvProfiles.DataSource = new UserBO().GetAllUsers();
gvProfiles.DataBind();
}
protected void ShowGrid()
{
fvProfiles.Visible = false;
gvProfiles.Visible = true;
btnAdd.Visible = true;
}
protected void HideGrid()
{
fvProfiles.Visible = true;
gvProfiles.Visible = false;
btnAdd.Visible = false;
}
protected void btnAdd_Click(object sender, EventArgs e)
{
HideGrid();
fvProfiles.ChangeMode(FormViewMode.Insert);
}
protected void InsertButton_Click(object sender, EventArgs e)
{
ShowGrid();
}
protected void InsertCancelButton_Click(object sender, EventArgs e)
{
ShowGrid();
}
protected void gvProfiles_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName =="Edit")
{
gvProfiles.Visible = false;
fvProfiles.Visible = true;
btnAdd.Visible = false;
fvProfiles.ChangeMode(FormViewMode.Edit);
odsProfiles.SelectParameters["UserId"].DefaultValue = e.CommandArgument.ToString();
odsProfiles.DataBind();
}
if (e.CommandName == "LogicalDelete")
{
int i = Convert.ToInt32(e.CommandArgument);
//call the userBO method to logically delete the record.
//new UserBO().DeleteUser(i);
}
if (e.CommandName == "Delete")
{
int i = Convert.ToInt32(e.CommandArgument);
//call the userBO method to delete the record.
new UserBO().DeleteUser(i);
}
}
protected void gvProfiles_RowEditing(object sender, GridViewEditEventArgs e)
{
BindGrid();
}
protected void UpdateButton_Click(object sender, EventArgs e)
{
ShowGrid();
}
protected void UpdateCancelButton_Click(object sender, EventArgs e)
{
ShowGrid();
}
protected void gvProfiles_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
BindGrid();
}
}
odsprofiles
是一個ObjectDataSource。
感謝您迴應,但gvProfiles.Rows collecton不包含清晰的定義,並沒有擴展方法Clear()可以找到。 – user3624391