Hi coder i have an createuser page in which i have some field and submit button
When i click on my submit button it will save details into database
aspx.cs code for createuser page:
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)
{
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();
}
}
}
now i have a search user page in which i have a textbox, gridview and search button when i enter name of any user and click on search button it will show user details inside gridview now i have an edit link inside gridview what i want is when i click on edit link it will redirect to createuser page where in place of submit button i want to show update button and when i make changes and click on update button details for the selected user which i select from edit link of search user page will update. how can i do that
aspx page of search user
<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>
Now i have an edit link inside gridview what i want is when i click on edit link it will redirect to createuser page where in place of submit button i want to show update button and when i make changes and click on update button details for the selected user which i select from edit link of search user page will update. how can i do that
Thanks in advance