• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1057
  • Last Modified:

Please Help..Urgetn Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

Hi Experts,

I am having problems with my datagrid and I hope as always there is an Expert around to help me.

I have a dataGrid with a link buttons, when I click on the link button expecting to be redirected to another page, I get this error "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index "

I can't figure out what this error is and I hope there is an expert as always to help me on my project.

below is the section of code that is given me problems.

private void dataGrid_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                  //fill the form with the details of the selected row
                  //mycomponent.FillDataset(callsLogged1);
                  
                  int index = dataGrid.SelectedIndex;

--error on this line--            string key = dataGrid.DataKeys[index].ToString();

                  dataView1.RowFilter = dataGrid.DataKeyField+ "='" + key + "'";
                  Response.Redirect("CallDetail.aspx?CallID=" + key );
            }//end selectedIndex method

Kind Regards
0
eryckop
Asked:
eryckop
  • 9
  • 6
  • 4
  • +2
1 Solution
 
gregoryyoungCommented:
add this around it ...

if(index >= 0) {
}

most likely there is no selected index when its fired ...

Greg
0
 
dunglaCommented:
change

int index = dataGrid.SelectedIndex;

to
int index = 0;
if (dataGrid.SelectedIndex >= 0)
{
index = dataGrid.SelectedIndex;
}
else
{
return
}
0
 
gregoryyoungCommented:
how exactly is that different from my post?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
fcnatraSoftware...Commented:
I see that is ASP.NET
Try filling the data into the datagrid in the PageLoad or some other place before handling that event: No matter if you did it in the previous roundtrip to the server, you should fill it again

Tell me if you got lucky with this
0
 
Bob LearnedCommented:
Greg, I don't see any difference.

Bob
0
 
gregoryyoungCommented:
Ok thought I might be going nuts here ...
0
 
Bob LearnedCommented:
0
 
gregoryyoungCommented:
0
 
Bob LearnedCommented:
I know, I like to help where I can, when I spot things like that.

Bob
0
 
eryckopAuthor Commented:
Hi All,
Thanks for the help so far, I have tweak my cde as suggested with and if statement wrap around to check the value of index. I am still getting the same error, indicating that the index is non-zero value.
Please your help is much appreciated.
Kind Regards.
0
 
gregoryyoungCommented:
ok ... what is DataKeys.Count when you enter the code ?

is it 0 by chance?

Greg
0
 
eryckopAuthor Commented:
Hi Greg,

DataKeys.Count is 0 (zero)

regards,
Eric
0
 
gregoryyoungCommented:
do you have viewstate turned on?

or have you reloaded the grid (note with keys viewstate should be turned on)
0
 
fcnatraSoftware...Commented:
Perhaps you did not see my previous answer.

You are getting DataKeys.Count = 0 because it is quite probable that your DataGrid is empty.

Try filling the data into the datagrid in the PageLoad or some other place before handling that event, no matter if you did it in the previous roundtrip to the server, and then try locating the SelectedIndex.

0
 
gregoryyoungCommented:
"Try filling the data into the datagrid in the PageLoad or some other place before handling that event: No matter if you did it in the previous roundtrip to the server, you should fill it again"

Cnatra: the whole concept of datakeys is to use them with viewstate (because on multi user systems you may not have the SAME data when you get back) You are absolutly NOT to reload the grid on every postback ... heres why.

example:

I have a page that reloads a grid in page load on every postback

You request page I return to you 5 rows.
John requests page I return to him 5 rows.
John deletes row 3, I return 4 rows to John.
John adds new row, I return 5 rows to John.
You click to edit row 4, if I don't use datakeys out of viewstate you are editting a different row than you clicked on because SelectedIndex will no longer point to the proper row. (a worse example is you clicking to delete a row). By using datakeys out of viewstate this is trappable.

Another easy example:
You request page I return to you 5 rows.
John requests page I return to him 5 rows.
John deletes row 3, I return for rows to John.
You click to edit Row 5 ... IndexOutOfRangeException

Hope this explains it.

Cheers,

Greg
0
 
eryckopAuthor Commented:
Hi Greg,
I am thinking perphaps if I copy and paste the entire code up her, you or someone could figure out my problems. Please find below the code at it is at the moment with the same error; the aspx code and then the code behind.

aspx code
--------------------------

<body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:image id="Image1" style="Z-INDEX: 108; LEFT: 10px; POSITION: absolute; TOP: 8px" runat="server"
                        Height="67px" Width="616px" ImageUrl="file:///C:\Inetpub\wwwroot\NewWebsupportProject\image\testbanner3.gif"></asp:image>
                  <table height="738" cellSpacing="1" cellPadding="1" width="126" bgColor="lightblue" border="0"       style="WIDTH: 126px; HEIGHT: 738px">
<tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr>
<tr></tr><tr></tr><tr></tr>
<TR><td valign="top">
<asp:Button id="CallLogbt" runat="server" Width="120px" Height="25px" Text="Call Logging" BackColor="LightGoldenrodYellow"BorderColor="#FFFFC0"></asp:Button>
<asp:Button id="AssManagerBt" runat="server" Width="120px" Height="25px" Text="Asset Manager"BackColor="LightGoldenrodYellow" BorderColor="#FFFFC0"></asp:Button>
<asp:Button id="SytemUserbt" runat="server" Width="120px" Height="25px" Text="New System User"      BackColor="LightGoldenrodYellow" BorderColor="#FFFFC0"></asp:Button>
<asp:Button id="ReportBt" runat="server" Height="25px" Width="120px" Text="Generate Report"       BackColor="LightGoldenrodYellow" BorderColor="#FFFFC0"></asp:Button>
<asp:Button id="Helpbt" runat="server" Width="120px" Height="25px" Text="Help" BackColor="LightGoldenrodYellow" BorderColor="#FFFFC0"></asp:Button>                              </td></TR></TR>      </table>
<asp:button id="addCallButton" style="Z-INDEX: 100; LEFT: 155px; POSITION: absolute; TOP: 80px" runat="server" Height="25px" Width="84px" Text="Add New Call"></asp:button>
<asp:label id="searchLabel" style="Z-INDEX: 101; LEFT: 242px; POSITION: absolute; TOP: 82px"      tabIndex="2" runat="server" Height="17px" Width="127px">Enter Text to Search
</asp:label>
<asp:textbox id="searchTextBox" style="Z-INDEX: 102; LEFT: 377px; POSITION: absolute; TOP: 82px" tabIndex="3" runat="server" Height="25px" Width="127px"></asp:textbox>
<asp:dropdownlist id="searchList" style="Z-INDEX: 103; LEFT: 509px; POSITION: absolute; TOP: 84px" tabIndex="4" runat="server" Height="25px" Width="88px"></asp:dropdownlist>
<asp:button id="goButton" style="Z-INDEX: 104; LEFT: 599px; POSITION: absolute; TOP: 81px" tabIndex="5" runat="server" Height="25px" Width="24px" Text="Go"></asp:button>
<asp:label id="summaryLabel" style="Z-INDEX: 106; LEFT: 155px; POSITION: absolute; TOP: 120px"      tabIndex="6" runat="server" Height="33px" Width="467px" Font-Size="X-Large" BackColor="#8080FF" Font-Bold="True">Summary of Logged Calls
</asp:label>
<asp:datagrid id=dataGrid style="Z-INDEX: 104; LEFT: 156px; POSITION: absolute; TOP: 169px" tabIndex=7 runat="server" Height="193px" Width="466px" AllowSorting="True"
 DataSource="<%# dataView1 %>" AllowPaging="True" ForeColor="Black" >
<EditItemStyle BackColor="White"></EditItemStyle>
<AlternatingItemStyle ForeColor="Black" BackColor="LightGoldenrodYellow"></AlternatingItemStyle>
<ItemStyle BackColor="White"></ItemStyle>
<HeaderStyle BackColor="LightBlue"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="Select" DataTextField="CallID" SortExpression="CallID" HeaderText="Call ID"
CommandName="Select"></asp:ButtonColumn>
<asp:BoundColumn DataField="Loggedby" SortExpression="Loggedby" HeaderText="Logged By"></asp:BoundColumn>
<asp:BoundColumn DataField="ExpectedDatetoComplete" SortExpression="ExpectedDatetoComplete" HeaderText="Date to Complete"
DataFormatString="{0:MM/dd/yyyy}"></asp:BoundColumn>
</Columns>
<PagerStyle NextPageText="Next &amp;gt;" PrevPageText="&amp;lt; Previous"></PagerStyle>
</asp:datagrid>
</form>
</body>
</HTML>


------------------------------

code behind, .cs code
--------------------------------

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.Windows.Forms;

namespace NewWebsupportProject
{
      /// <summary>
      /// Summary description for SummaryPage.
      /// </summary>
      public class SummaryPage : System.Web.UI.Page
      {
            protected System.Web.UI.WebControls.Button addCallButton;
            protected System.Web.UI.WebControls.Label searchLabel;
            protected System.Web.UI.WebControls.TextBox searchTextBox;
            protected System.Web.UI.WebControls.DropDownList searchList;
            protected System.Web.UI.WebControls.Button goButton;
            protected System.Web.UI.WebControls.Label summaryLabel;
            protected System.Web.UI.WebControls.DataGrid dataGrid;
            private System.ComponentModel.Container components = null;

            //ADO adapters

            protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
            protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
            protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
            protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
            protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
            protected System.Data.OleDb.OleDbConnection oleDbConnection1;
            protected System.Data.OleDb.OleDbDataReader dataReader;

            protected System.Data.DataTable dataTable1 = new DataTable();
            protected System.Data.DataView dataView1;
            protected System.Web.UI.WebControls.Image Image1;
            protected System.Web.UI.WebControls.Button ReportBt;
            protected System.Web.UI.WebControls.Button CallLogbt;
            protected System.Web.UI.WebControls.Button AssManagerBt;
            protected System.Web.UI.WebControls.Button Helpbt;
            protected System.Web.UI.WebControls.Button SytemUserbt;
            //protected System.Web.UI.WebControls.DataGrid dataGrid;

            protected static string sortString = "Title";

            //
      
            private void Page_Load(object sender, System.EventArgs e)
            {
                  // Put user code to initialize the page here
                  // test if the page was loaded
                  
                  if ( !IsPostBack )
                  {
                        try
                        {
                              // connect to the database
                              searchList.Items.Clear();
                              searchList.Items.Add("-select-");

                              oleDbConnection1.Open();
                              oleDbSelectCommand1.CommandText = "SELECT UserType FROM UserTypes " +
                                    "WHERE UserTypeID<>4 AND UserTypeID<>5";
                              // Execute Query
                              dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();

                              //fill searList with data from the database
                              while( dataReader.Read() )
                                    searchList.Items.Add( dataReader.GetString( 0 )); //+
                              //" " + dataReader.GetString( 1 ));
                        }
                              // Display massage if no database found

                        catch( System.Data.OleDb.OleDbException )
                        {
                              summaryLabel.Text = "Server Error: Unable to Access Database";
                        }
                        finally
                        {
                              if (oleDbConnection1.State==ConnectionState.Open)
                              {
                                    //dataReader.Close();
                                    oleDbConnection1.Close();
                              }
                        }
                        //Fill dataGrid with results
                        FillGrid();

                  }
                  

            } // end of Page Load

            //clear out any resources

            /*public override void Dispose( bool disposing )
            {
                  if(disposing)
                  {
                        if(components !=null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose ( disposing );
            } */

            // retrieve query results from the database
            public void FillGrid()
            {
                  // set dataGrid to be visible
                  oleDbConnection1.Close();
                  dataGrid.Visible = true;
                  if (dataReader !=null)
                        dataReader=null;
                  try
                  {
                        oleDbConnection1.Open();

                        // select record from the LoggedCall Table
                        oleDbDataAdapter1.SelectCommand.CommandText =
                              "SELECT LoggedCall.CallID, LoggedCall.Title, LoggedCall.AssignedTo, LoggedCall.Loggedby, LoggedCall.ExpectedDatetoComplete " +
                              "FROM LoggedCall";
                        oleDbDataAdapter1.Fill(dataTable1);
                        dataView1 = new DataView( dataTable1 );
                        dataView1.Sort = sortString;
                        
                        // Bind datagrid to source
                        dataGrid.DataBind();

                  }
                        // catch database error that may results in reading data from the database

                  catch( System.Data.OleDb.OleDbException )
                  {
                        summaryLabel.Text = "Server Error: Unable to Access LoggedCall Table";
                  }

                  //Close all open connections
                  finally
                  {
                        if(oleDbConnection1.State==ConnectionState.Open)
                        {
                              oleDbConnection1.Close();
                        }
                  }

            }

            // set current page to next page on sorting
            public void OnNewPage( object sender, DataGridPageChangedEventArgs e )
            {
                  dataGrid.CurrentPageIndex = e.NewPageIndex;

                  dataView1.Sort = sortString;
                  // rebind data
                  dataGrid.DataBind();
            }// end of Onnewpage

            //method to handle sort event
            public void dataGrid_SortCommand( object source,
                  System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
            {
                  //get table to sort
                  sortString = e.SortExpression.ToString();
                  dataView1.Sort = sortString;
                  //rebind data
                  dataGrid.DataBind();
            }// end of sort method

            private void dataGrid_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                  //fill the form with the details of the selected row
                  //mycomponent.FillDataset(callsLogged1);
                  
                  int index = 0;
                  if(dataGrid.SelectedIndex >= 0)
                  {
                        index = dataGrid.SelectedIndex;
                        int count = dataGrid.DataKeys.Count;
                        string key = dataGrid.DataKeys[index].ToString();
                        dataView1.RowFilter = dataGrid.DataKeyField+ "='" + key + "'";
                        Response.Redirect("CallDetail.aspx?CallID=" + key );
                  }
                  else
                  {
                        return;

                        //MessageBox.Show("No Item Selected"," ", MessageBoxButtons.OK);
                  }
            }//end selectedIndex method

            private void goButton_Click(object sender, System.EventArgs e)
            {
                  // search by text

                  // check if the connections are closed before opening new connections
                  if(oleDbConnection1.State==ConnectionState.Closed)
                  {
                        oleDbConnection1.Open();
                  }
                  
                  // search by staff
                  if (searchList.SelectedIndex.Equals(1))
                  {
                        oleDbDataAdapter1.SelectCommand.CommandText ="SELECT LoggedCall.CallID, LoggedCall.Title, LoggedCall.AssignedTo, LoggedCall.Loggedby, LoggedCall.ExpectedDatetoComplete " +
                              "FROM LoggedCall INNER JOIN Users ON LoggedCall.Loggedby = Users.UserId " +
                              "WHERE (Users.Name = "+"'"+searchTextBox.Text+"'" +")";
                        //      dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader(CommandBehavior.CloseConnection);
                        
                        try
                        {
                              //if(dataReader.HasRows)
                              //{
                              oleDbDataAdapter1.Fill( dataTable1 );
                              dataView1 = new DataView( dataTable1 );
                              dataView1.Sort = sortString;
                              // Bind datagrid to source
                              dataGrid.DataBind();
                              //}
                        }
                        
                        catch( System.Data.OleDb.OleDbException )
                        {
                              summaryLabel.Text = "No Record found";
                        }

                        finally
                        {
                              if(oleDbConnection1.State == ConnectionState.Open)
                                    oleDbConnection1.Close();
                        }
                  }
                        //search UserType by prospect

                  else if (searchList.SelectedIndex.Equals(2))
                  {
                        if(oleDbConnection1.State == ConnectionState.Closed)
                        {
                              oleDbConnection1.Open();
                        }
                        //set the sql string to search for Call Title matching input string
                        //Searchtextbox.Text = "Call Title";
                        oleDbDataAdapter1.SelectCommand.CommandText ="SELECT LoggedCall.CallID, LoggedCall.Title, LoggedCall.AssignedTo, LoggedCall.Loggedby " +
                              "FROM LoggedCall INNER JOIN Users ON LoggedCall.Loggedby = Users.UserId " +
                              "WHERE (LoggedCall.Title = "+"'"+searchTextBox.Text+"'" +")";
                        try
                        {
                              //  if(dataReader.HasRows)
                              //{
                              oleDbDataAdapter1.Fill( dataTable1 );
                              dataView1 = new DataView( dataTable1 );
                              dataView1.Sort = sortString;
                              // Bind datagrid to source
                              dataGrid.DataBind();
                              //}
                        }

                        catch( System.Data.OleDb.OleDbException )
                        {
                              summaryLabel.Text = "No Record found";
                        }
                        finally
                        {
                              if(oleDbConnection1.State == ConnectionState.Open)
                                    oleDbConnection1.Close();
                        }
                  }
                  //search by UserType Client

                  if (searchList.SelectedIndex.Equals(3))
                  {
                        if(oleDbConnection1.State==ConnectionState.Closed)
                        {
                              oleDbConnection1.Open();
                        }
                        //set the sql string to search for Text in the call Description matching input string
                        //Searchtextbox.Text = "Text";

                        oleDbDataAdapter1.SelectCommand.CommandText ="SELECT LoggedCall.CallID, LoggedCall.Title, LoggedCall.AssignedTo, LoggedCall.Loggedby " +
                              "FROM LoggedCall INNER JOIN Users ON LoggedCall.Loggedby = Users.UserId " +
                              "WHERE (LoggedCall.CallDescription LIKE "+"'%"+searchTextBox.Text+"%'" +")";
                        //dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader(CommandBehavior.CloseConnection);
            //            DataSet ch = new DataSet();
                        //oleDbDataAdapter1.Fill(ch, "CallHistory");
                        
                        try
                        
                        {

                              oleDbDataAdapter1.Fill( dataTable1 );
                              dataView1 = new DataView( dataTable1 );
                              dataView1.Sort = sortString;
                              // Bind datagrid to source
                              dataGrid.DataBind();
                                    
                              

                        }
                        catch( System.Data.OleDb.OleDbException )
                        {
                              summaryLabel.Text = "No Record found";
                        }
                        finally
                        {
                              if(oleDbConnection1.State == ConnectionState.Open)
                                    oleDbConnection1.Close();
                        }
                  }


      }//end GoButton method

            #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.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
                  this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
                  this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
                  this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
                  this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
                  this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
                  //
                  // oleDbDataAdapter1
                  //
                  this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;
                  this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
                  //
                  // oleDbInsertCommand1
                  //
                  this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
                  //
                  // oleDbConnection1
                  //
                  this.oleDbConnection1.ConnectionString = @"Integrated Security=SSPI;Packet Size=4096;Data Source=""ERYCKOP-002"";Tag with column collation when possible=False;Initial Catalog=Project-2;Use Procedure for Prepare=1;Auto Translate=True;Persist Security Info=False;Provider=""SQLOLEDB.1"";Workstation ID=""ERYCKOP-002"";Use Encryption for Data=False";
                  //
                  // oleDbSelectCommand1
                  //
                  this.oleDbSelectCommand1.Connection = this.oleDbConnection1;
                  this.CallLogbt.Click += new System.EventHandler(this.CallLogbt_Click);
                  this.AssManagerBt.Click += new System.EventHandler(this.AssManagerBt_Click);
                  this.SytemUserbt.Click += new System.EventHandler(this.SytemUserbt_Click);
                  this.addCallButton.Click += new System.EventHandler(this.addCallButton_Click);
                  this.goButton.Click += new System.EventHandler(this.goButton_Click);
                  this.dataGrid.SelectedIndexChanged += new System.EventHandler(this.dataGrid_SelectedIndexChanged);
                  this.Load += new System.EventHandler(this.Page_Load);

            }
            #endregion

            private void addCallButton_Click(object sender, System.EventArgs e)
            {
                  Response.Redirect("AddNewCall.aspx");
            }

            private void CallLogbt_Click(object sender, System.EventArgs e)
            {
                  //Response.Redirect("CallList.aspx");
                  Response.Redirect("SummaryPage.aspx");
            }


            private void AssManagerBt_Click(object sender, System.EventArgs e)
            {                  
                  Response.Redirect("AssetMenu.aspx");
            }

            private void Helpbt_Click(object sender, System.EventArgs e)
            {
            
            }

            // Redirect to a page to add new system user. the user must alread be a staff member
            private void SytemUserbt_Click(object sender, System.EventArgs e)
            {
                  Response.Redirect("NewUser.aspx");
            
            }

            private void ReportBt_Click(object sender, System.EventArgs e)
            {
            
            }

      }
}

-----------------------------------

I hope this will help you to help me.

Reagrds,

Eric
0
 
fcnatraSoftware...Commented:
           private void Page_Load(object sender, System.EventArgs e)
            {
                  if (!this.IsPostBack) FillDataGrid();

            }

            private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                  this.Label1.Text = "DG DataKeys: " + this.DataGrid1.DataKeys.Count.ToString();
            }

            private void FillDataGrid()
            {
                  this.sqlDataAdapter1.Fill(this.dataSet11);

                  // SPECIFYING THE DATAKEY SEEMS TO RESULT IN DATAKEY VALUES
                  DataColumn[] keys = new DataColumn[1];
                  keys[0] = this.dataSet11.Tables["Customers"].Columns[0];
                  this.dataSet11.Tables["Customers"].PrimaryKey = keys;

                  this.dataView1 = this.dataSet11.Tables["Customers"].DefaultView;
                  this.DataGrid1.DataBind();
                  this.Label1.Text = this.DataGrid1.DataKeyField;
            }
0
 
fcnatraSoftware...Commented:
...specifying the datakeyfield of the datagrid, I meant

Forget the code below the commented line in the previous post. I think that the question is that you have not initialized the DataKeyField. The bode below the commented line should be the setting of the DataKeyField property.

G.Luck.
0
 
eryckopAuthor Commented:
Hi
Trying your code I get an error not initialised oobject on the line Keys[0] = this.dataSet11.Tables["Customers"].Column.
It appears to me that the line DataColumns[] keys = new DataColumns[1] is the line that does the initialising.

Also, I am trying to pass this key from the record selected to another "Response.Redirect("CallDetail.aspx?CallID=" + key );" in your code where would I do that.

Thanks for your help.

regards.
0
 
gregoryyoungCommented:
<asp:datagrid id=dataGrid style="Z-INDEX: 104; LEFT: 156px; POSITION: absolute; TOP: 169px" tabIndex=7 runat="server" Height="193px" Width="466px" AllowSorting="True"
 DataSource="<%# dataView1 %>" AllowPaging="True" ForeColor="Black" >

add your datakeyfield to the definition

ex:

DataKeyField="CustomerId"

Cheers,

Greg
0
 
eryckopAuthor Commented:
Hi Greg,
thanks for your tip, I have got yhe DataField definition in palce DataKeyField="CallID", I am getting this error "Cannot find column [CAllID]".
even though this column is dispalyed in the datagrid.
do you have any idea what this might be?

Regards,

Eric
0
 
eryckopAuthor Commented:
Hi Greg,

I have found a way around the error, all I added dataGrid.DataFiledKey=key and now it is working fine

Thanks very much for your lhelp and thanks to allwho contributed to this post.

I have another problem to do with paging, when I click on the next link to display the next set of record nothing happens. I have combed around my code and I can't find anyway I have gone wrong.

if I am not asking too much could you help me with this paging problem.

Regards,
Eric
0
 
gregoryyoungCommented:
I am not seeing where you are tieing your event for page change ... see here for an example.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskspecifyingpagingbehaviorindatagridwebcontrol.asp

Greg
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 9
  • 6
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now