想要向asp.net C#应用程序添加“编辑”功能,以便用户的某个角色可以创建由“标准”用户提交的记录的编辑版本。原始记录保留在表A中,编辑后的版本存储在表B中(引用原始记录)。我希望能够添加到这个中的是,如果编辑器点击他们已编辑的记录的编辑按钮,以便能够询问他们(通过弹出窗口?)他们是否想要创建新的编辑记录,或创建新编辑的记录并根据此答案加载页面。
目前,用户点击gridview上的编辑问题链接按钮:
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="Edit" CommandArgument='<%# Eval("QuestionID") %>' runat="server" CommandName="editQuestion">Edit Question</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
通过rowcommand语句启动Edit Question页面:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "viewQuestion")
{
Session["PageIndex"] = GridView1.PageIndex;
Session["QuestionId"] = e.CommandArgument.ToString();
Response.Redirect("~/Review/ReviewDetail.aspx?Id=" + Convert.ToString(Session["QuestionId"]));
}
if(e.CommandName == "editQuestion")
{
Session["PageIndex"] = GridView1.PageIndex;
Session["QuestionId"] = e.CommandArgument.ToString();
Response.Redirect("~/Review/EditQuestion.aspx?Id=" + Convert.ToString(Session["QuestionId"]));
}
}
使用存储过程加载页面,该存储过程从表A中提取适用的记录:
using (Conn)
{
SqlCommand command = new SqlCommand("sp_CloneSElect", Conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@QuestionID", SqlDbType.BigInt));
command.Parameters["@QuestionID"].Value = Convert.ToInt32(Request["Id"]);
Conn.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
txt_ImageID.Text = reader["ImageID"].ToString();
txt_Date.Text = reader["SubmitDate"].ToString();
txt_Stem.Text = reader["Stem"].ToString();
txt_RespA.Text = reader["RespA"].ToString();
txt_RespB.Text = reader["RespB"].ToString();
txt_RespC.Text = reader["RespC"].ToString();
txt_RespD.Text = reader["RespD"].ToString();
txt_RespE.Text = reader["RespE"].ToString();
DDResponse.SelectedValue = reader["Answer"].ToString();
txt_Critique.Text = reader["Critique"].ToString();
txt_KeyObjective.Text = reader["KeyObjective"].ToString();
txt_References.Text = reader["References"].ToString();
DDPractice1.SelectedValue = reader["PracticeArea1"].ToString();
DDPractice2.SelectedValue = reader["PracticeArea2"].ToString();
DDPractice3.SelectedValue = reader["PracticeArea3"].ToString();
DDPractice4.SelectedValue = reader["PracticeArea4"].ToString();
txt_QuestionID.Text = reader["Id"].ToString();
txt_IsCloneOf.Text = reader["IsCloneOf"].ToString();
}
reader.Close();
DataTable dt = new DataTable();
using (Conn)
{
SqlDataAdapter ad = new SqlDataAdapter("SELECT QuestionID, Images2.ImageID, ImageFile, ImageContent, ImageName, SEQ_NUM from qimages join Images2 on qimages.imageid = images2.imageid where QuestionID = @QuestionID", Conn);
ad.SelectCommand.Parameters.Add("QuestionID", SqlDbType.BigInt).Value = txt_QuestionID.Text;
ad.Fill(dt);
}
dlImages.DataSource = dt;
dlImages.DataBind();
}
我可以弄清楚如何让底层存储过程执行从表b中提取的逻辑(如果存在),否则表a ,,但不知道如何向用户询问问题并将新变量添加到对存储过程的输入,或者如果根据用户对“您已经编辑过此问题,是否要查看此记录或创建新编辑的版本?”的问题的答案更改更改存储过程会更容易。