フィールドと送信ボタンがある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();
}
}
}
今、ユーザーの名前を入力して検索ボタンをクリックすると、テキストボックス、グリッドビュー、検索ボタンがある検索ユーザーページがあり、グリッドビュー内にユーザーの詳細が表示されるようになりました。グリッドビュー内に編集リンクがあります。編集リンクをクリックすると、送信ボタンの代わりに更新ボタンを表示したい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内に編集リンクを持っています。編集リンクをクリックすると、送信ボタンの代わりに更新ボタンを表示したいcreateuserページにリダイレクトされ、変更を加えて選択した更新ボタンの詳細をクリックすると、検索ユーザーページの編集リンクから選択したユーザーが更新されます。どうやってやるの?