我有一個createuser頁面,其中我有一些字段並提交按鈕。如何更改按鈕的功能以及它的文本
當我點擊我的提交按鈕將信息保存到數據庫
aspx.cs代碼CREATEUSER頁:
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我想要的是當我點擊編輯鏈接它將重定向到createuser頁在哪裏提交按鈕的地方我想顯示更新按鈕,當我做出更改並點擊更新對接關於我從搜索用戶頁面的編輯鏈接中選擇的用戶的詳細信息將更新。我怎麼能做到這一點搜索用戶的
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編輯鏈接我想要的是,當我點擊編輯鏈接它將重定向到創建用戶頁面在哪裏代替提交按鈕我想要顯示更新按鈕,當我進行更改並單擊更新按鈕的詳細信息選定用戶,我從搜索用戶頁面的編輯鏈接中選擇將更新。我怎樣才能做到這一點?