مثل اینکه کسی به تاپیک من توجه نکرده، مشکلمو بیشتر توضیح میدم :
من می خوام تو GridView با کلیک روی دکمه ویرایش به صفحه Register برم و اونجا اطلاعات اون کاربر خاص رو نمایش بدم ، حالا مشکل من دقیقا" اینجاست که نمی تونم یه Username خاص رو بگیرم.از کدهای زیر استفاده می کنم ولی جواب نمی ده:
foreach (GridViewRow gvRow in GridView1.Rows)
{
Application["update"] = "1";
// Application["EditUser"] = gvRow.FindControl("lblUserName").Controls[0];
Label1.Text = gvRow.Cells[6].Controls[0].ToString();
Application["EditUser"] =gvRow.Cells[6].Controls[0];
Response.Redirect("Register.aspx");
}
lblUserName یه Label است که تو html تعریفش کردم و به "UserName" تو data base وصلش کردم.برای application["EditUser"] هم تو صفحه Register یه تابع نوشتم به نام User_Bind_Update
publicvoid Bind_User_Update(string username)
{
SqlConnection cnn = newSqlConnection();
cnn.ConnectionString = "Data Source=localhost;Initial Catalog=library;Integrated Security=True;";
SqlCommand cmd = newSqlCommand();
cmd.Connection = cnn;
SqlDataReader dr;
try
{
cnn.Open();
cmd.CommandText = "SELECT * FROM [User] WHERE [UserName]=@UserName";
cmd.Parameters.Add("@UserName", username);
dr = cmd.ExecuteReader();
while (dr.Read())
{
this.txtUsername.Text = (dr["UserName"]).ToString();
this.txtAddress.Text = (dr["Address"].ToString());
this.txtMail.Text = (dr["Email"].ToString());
this.txtName.Text = (dr["Name"].ToString());
this.txtFamily.Text = (dr["Family"].ToString());
this.txtPhone.Text = (dr["telephone"].ToString());
this.txtNo.Text = (dr["userId"].ToString());
this.txtBirthNo.Text = (dr["BirthCertificateNo"].ToString());
this.DropDownList1.SelectedValue = (dr["levelId"].ToString());
this.DropDownList2.SelectedValue = (dr["StudentStatusId"].ToString());
this.Image1.ImageUrl = (dr["imagePath"].ToString());
}
cnn.Close();
dr.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
cnn.Close();
}
}
و تو page_load فراخوانی کردم:
if(Application["update"]=="1")
{
Bind_User_Update(Application["EditUser"].ToString());
}
حالا مشکلم اینجاست که اصلا" تو while(dr.read()) منی ره .
تو رو خدا یکی کمکم کنه دیگه باید چی کار کنم؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟