سلام، خسته نباشید
پروژه ای می نویسم که در یکی از جداول بانک درخواستهایی از کاربران متفاوت ذخیره می شه، حالا اگه بخوام گرید ویو را طوری تنظیم کنم که هنگام لود شدن صفحه براساس نام کاربری خاصی فیلتر بشه و تنها درخواستهایی را نمایش بده که مربوط به نام کاربری تعریف شده باشه از چه روشی باید استفاده کنم.
(البته پروژه من asp.net نوشته می شه، ولی کدها در C# language است. )
کد من به صورت زیراست.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
SqlConnection conn = new SqlConnection(ConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select Code_re,Topic,Text,CommentMG from RequstTB where UserID=@UserID";
cmd.Parameters.AddWithValue("@UserID", ClassLogin.Username);
cmd.Connection = conn;
conn.Open();
SqlDataReader rd = cmd.ExecuteReader();
int i = 1;
while (rd.Read())
{
GridView1.Rows[1].Cells[1].Text = rd["Code_re"].ToString();
GridView1.Rows[1].Cells[2].Text = ClassLogin.Username;
GridView1.Rows[1].Cells[3].Text = rd["Topic"].ToString();
GridView1.Rows[1].Cells[4].Text = rd["Text"].ToString();
GridView1.Rows[1].Cells[5].Text = rd["CommentMG"].ToString();
i++;
}
conn.Close();
}
و خطایی که موقع اجرا می ده :
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
در خط 14