rosemary

rosemary

  • NA
  • 57
  • 20.2k

Error : Index was outside the bounds of the array

May 29 2018 4:34 AM
There is a problem in my code and i am not aware how to resolve this .
 
My Error is Index was outside the bounds of the array. when i am passing 1 or 2 value through query string it gives error. please help me and resolve my problem if anybody can.
 
Thnkx in adv.
  1. GridViewRow gr = (GridViewRow)((Button)sender).NamingContainer;  
  2. string userid = gdvdetails.DataKeys[gr.RowIndex].Values[0].ToString();  
  3. string jobid = gdvdetails.DataKeys[gr.RowIndex].Values[1].ToString();   
  4. Response.Redirect("view_userprofile.aspx?cid=" + userid + "gid=" + jobid);  
  5. protected void Page_Load(object sender, EventArgs e)  
  6. {  
  7. if (!IsPostBack)  
  8. {  
  9. try  
  10. {  
  11. if (Request.QueryString["cid"].ToString() != "")  
  12. {  
  13. //string id = Request.QueryString["cid"].ToString();  
  14. var q1 = (Request.QueryString.ToString());  
  15. var qs = q1.Split('&');  
  16. var qs1 = (qs[0].Split('='));  
  17. hdfuserid.Value = qs1[1];  
  18. var qs2 = qs[1].Split('=');  
  19. hdfjobid.Value = qs2[1];  
  20. Session["vid"] = hdfjobid.Value.ToString();  
  21. SqlCommand cmd = new SqlCommand("select * from user_profile where uid='" + hdfuserid.Value + "'and jid='" + hdfjobid + "'", Con);  
  22. SqlDataAdapter da = new SqlDataAdapter(cmd);  
  23. DataTable dt = new DataTable();  
  24. da.Fill(dt);  
  25. if (dt.Rows.Count > 0)  
  26. {  
  27. lblfname.Text = dt.Rows[0]["fname"].ToString();  
  28. lbllname.Text = dt.Rows[0]["lname"].ToString();  
  29. lbladdress.Text = dt.Rows[0]["address"].ToString();  
  30. lblfathername.Text = dt.Rows[0]["fathername"].ToString();  
  31. lblmothername.Text = dt.Rows[0]["mothername"].ToString();  
  32. lblfoccu.Text = dt.Rows[0]["foccu"].ToString();  
  33. lblmoccu.Text = dt.Rows[0]["moccu"].ToString();  
  34. lblmob.Text = dt.Rows[0]["mob"].ToString();  
  35. lblplace.Text = dt.Rows[0]["place"].ToString();  
  36. lbl10percen.Text = dt.Rows[0]["tenth"].ToString();  
  37. lblplustwo.Text = dt.Rows[0]["plustwo"].ToString();  
  38. lbldegree.Text = dt.Rows[0]["degree"].ToString();  
  39. lblkeyskill.Text = dt.Rows[0]["keyskills"].ToString();  
  40. lblexp.Text = dt.Rows[0]["exp"].ToString();  
  41. }  
  42. }  
  43. }  
  44. catch (Exception ex)  
  45. {  
  46. Response.Write("Error");  
  47. }  
  48. }  
  49. }  

Answers (2)