alanvoon
asked on
Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
Tried very hard to solve the error above but I don't really know what does it mean, please help. My codes are as below :
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls ;
using System.Data.SqlClient;
namespace RealTimePortal
{
/// <summary>
/// Summary description for Directory.
/// </summary>
public class Directory : System.Web.UI.Page
{
protected string u_name;
protected System.Data.SqlClient.SqlC onnection connection1;
protected System.Data.SqlClient.SqlC onnection connection2;
protected System.Data.SqlClient.SqlC onnection WebHostConn;
protected System.Data.SqlClient.SqlC ommand command1;
protected System.Data.SqlClient.SqlD ataAdapter SqlDataAdapter1;
protected DataSet m_ds = new DataSet();
protected System.Web.UI.WebControls. Button Button2;
protected System.Web.UI.WebControls. Label Label1;
protected System.Web.UI.WebControls. Label Label2;
protected System.Web.UI.WebControls. DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
u_name = Request.QueryString["u_nam e"];
//connection1 = new SqlConnection("server=loca lhost;data base=PORTA L DONE;Trusted_Connection=ye s");
System.Data.SqlClient.SqlC onnection WebHostConn = new SqlConnection ("data source=66.102.133.244; initial catalog=sanath;integrated security=false;user id=koongaik;password=koong aik1051");
command1 = new SqlCommand("SP_udirSel",We bHostConn) ;
command1.CommandType = CommandType.StoredProcedur e;
SqlParameter uname = new SqlParameter("@uname", SqlDbType.VarChar,50);
uname.Value = u_name;
command1.Parameters.Add(un ame);
SqlParameter a1 = new SqlParameter("@a1", SqlDbType.VarChar,50);
a1.Value = "";
command1.Parameters.Add(a1 );
SqlParameter a2 = new SqlParameter("@a2", SqlDbType.VarChar,50);
a2.Value = "";
command1.Parameters.Add(a2 );
SqlParameter a3 = new SqlParameter("@a3", SqlDbType.VarChar,50);
a3.Value = "";
command1.Parameters.Add(a3 );
SqlParameter a4 = new SqlParameter("@a4", SqlDbType.VarChar,50);
a4.Value = "";
command1.Parameters.Add(a4 );
SqlParameter a5 = new SqlParameter("@a5", SqlDbType.VarChar,50);
a5.Value = "";
command1.Parameters.Add(a5 );
SqlDataAdapter1 = new SqlDataAdapter();
SqlDataAdapter1.SelectComm and = command1;
SqlDataAdapter1.SelectComm and.Comman dType = CommandType.StoredProcedur e;
SqlDataAdapter1.Fill(m_ds, "Directory ");
DataGrid1.DataSource = m_ds;
if (!IsPostBack)
{
DataGrid1.DataBind();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button2.Click += new System.EventHandler(this.B utton2_Cli ck);
this.DataGrid1.ItemCommand += new System.Web.UI.WebControls. DataGridCo mmandEvent Handler(th is.DataGri d1_ItemCom mand);
this.DataGrid1.SelectedInd exChanged += new System.EventHandler(this.D ataGrid1_S electedInd exChanged) ;
this.Load += new System.EventHandler(this.P age_Load);
}
#endregion
private void DataGrid1_ItemCommand(obje ct source, System.Web.UI.WebControls. DataGridCo mmandEvent Args e)
{
string clickID = e.Item.Cells[5].Text;
if (e.CommandName == "Select")
{
Response.Redirect(clickID) ;
}
}
private void Button2_Click(object sender, System.EventArgs e)
{
Response.Redirect("Home.as px?u_name= " + u_name);
}
private void DataGrid1_SelectedIndexCha nged(objec t sender, System.EventArgs e)
{
}
}
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls
using System.Data.SqlClient;
namespace RealTimePortal
{
/// <summary>
/// Summary description for Directory.
/// </summary>
public class Directory : System.Web.UI.Page
{
protected string u_name;
protected System.Data.SqlClient.SqlC
protected System.Data.SqlClient.SqlC
protected System.Data.SqlClient.SqlC
protected System.Data.SqlClient.SqlC
protected System.Data.SqlClient.SqlD
protected DataSet m_ds = new DataSet();
protected System.Web.UI.WebControls.
protected System.Web.UI.WebControls.
protected System.Web.UI.WebControls.
protected System.Web.UI.WebControls.
private void Page_Load(object sender, System.EventArgs e)
{
u_name = Request.QueryString["u_nam
//connection1 = new SqlConnection("server=loca
System.Data.SqlClient.SqlC
command1 = new SqlCommand("SP_udirSel",We
command1.CommandType = CommandType.StoredProcedur
SqlParameter uname = new SqlParameter("@uname", SqlDbType.VarChar,50);
uname.Value = u_name;
command1.Parameters.Add(un
SqlParameter a1 = new SqlParameter("@a1", SqlDbType.VarChar,50);
a1.Value = "";
command1.Parameters.Add(a1
SqlParameter a2 = new SqlParameter("@a2", SqlDbType.VarChar,50);
a2.Value = "";
command1.Parameters.Add(a2
SqlParameter a3 = new SqlParameter("@a3", SqlDbType.VarChar,50);
a3.Value = "";
command1.Parameters.Add(a3
SqlParameter a4 = new SqlParameter("@a4", SqlDbType.VarChar,50);
a4.Value = "";
command1.Parameters.Add(a4
SqlParameter a5 = new SqlParameter("@a5", SqlDbType.VarChar,50);
a5.Value = "";
command1.Parameters.Add(a5
SqlDataAdapter1 = new SqlDataAdapter();
SqlDataAdapter1.SelectComm
SqlDataAdapter1.SelectComm
SqlDataAdapter1.Fill(m_ds,
DataGrid1.DataSource = m_ds;
if (!IsPostBack)
{
DataGrid1.DataBind();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button2.Click += new System.EventHandler(this.B
this.DataGrid1.ItemCommand
this.DataGrid1.SelectedInd
this.Load += new System.EventHandler(this.P
}
#endregion
private void DataGrid1_ItemCommand(obje
{
string clickID = e.Item.Cells[5].Text;
if (e.CommandName == "Select")
{
Response.Redirect(clickID)
}
}
private void Button2_Click(object sender, System.EventArgs e)
{
Response.Redirect("Home.as
}
private void DataGrid1_SelectedIndexCha
{
}
}
}
ASKER
I have tried the above code, but the same error still persists, would somebody please give me a detailed explanation of the error ?? Please help...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
string clickID = e.Item.Cells[5].Text;
Check the count of cells to validate that 5 is a valid index :
if (e.Item.Cells.Count >= 6)
{
string clickID = e.Item.Cells[5].Text; //Cells[5] is the 6th cell
}