我有一个 createuser 页面,其中有一些字段和提交按钮。
当我点击我的提交按钮时,它会将详细信息保存到数据库中
createuser 页面的 aspx.cs 代码:
protected void btnSubmit_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["WebGallery"].ToString()))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
string strSQL = "SELECT * FROM NewUser WHERE UserName = '" + tbName.Text + "'";
da.SelectCommand = new SqlCommand(strSQL);
da.SelectCommand.Connection = con;
da.Fill(dt);
if (dt.Rows.Count > 0) // Means first name is already present
{
lblmsg.Text = "This user is already added!";
}
else if (dt.Rows.Count == 0)
{
lblmsg.Visible = false;
string username = tbName.Text;
string pwd=tbPassword.Text;
string Confirmpwd = tbConfirmPassword.Text;
string Email = tbEmailID.Text;
string department = ddlDepartment.SelectedValue;
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "Insert into NewUser(UserName,Password,ConfirmPassword,EmailID,DepartmentName)values('" + tbName.Text + "','" + tbPassword.Text + "','"+tbConfirmPassword.Text+"','" + tbEmailID.Text + "','" + ddlDepartment.SelectedValue + "')";
cmd.Parameters.AddWithValue("@FirstName", tbName.Text.Trim());
cmd.Parameters.AddWithValue("@LastName", tbPassword.Text.Trim());
cmd.Parameters.AddWithValue("@DomainID", tbConfirmPassword.Text.Trim());
cmd.Parameters.AddWithValue("@EmailID", tbEmailID.Text.Trim());
cmd.Parameters.AddWithValue(@"RoleType", ddlDepartment.SelectedValue);
cmd.ExecuteNonQuery();
}
con.Close();
tbName.Text = "";
tbPassword.Text = "";
tbConfirmPassword.Text = "";
tbEmailID.Text = "";
tbName.Focus();
}
}
}
现在我有一个搜索用户页面,其中有一个文本框、gridview 和搜索按钮,当我输入任何用户的名称并单击搜索按钮时,它将在 gridview 中显示用户详细信息现在我在 gridview 中有一个编辑链接我想要的是什么时候我单击编辑链接,它将重定向到创建用户页面,代替提交按钮,我想显示更新按钮,当我进行更改并单击从搜索用户页面的编辑链接中选择的所选用户的更新按钮详细信息时,将更新. 我怎样才能做到这一点
搜索用户的aspx页面
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="ID"
DataNavigateUrlFormatString="~/CreateUser.aspx?ID={0}"
HeaderText="Edit" NavigateUrl="~/CreateUser.aspx" Text="Edit"/>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
aspx.cs 代码:
protected void BindGrid()
{
if ((tbSearchUser.Text.Length == 0))
{
lblMessage.Text = "Search Box cannot be empty! Please put something to search.";
}
con.Open();
string query = "Select * from NewUser where UserName like'" + tbSearchUser.Text + "'";
da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
GridView1.Dispose();
con.Close();
}
protected void btnSearchUser_Click(object sender, EventArgs e)
{
this.BindGrid();
}
现在我在gridview中有一个编辑链接我想要的是当我点击编辑链接时它会重定向到createuser页面代替提交按钮我想显示更新按钮以及当我进行更改并单击所选更新按钮的详细信息我从搜索用户页面的编辑链接中选择的用户将更新。我怎样才能做到这一点?