dekempeneer
asked on
error in asp.net
In my aspx file I HAD :
<asp:AccessDataSource id="AccessDataSource1" DataFile="data\DBS.mdb" runat="server" selectcommand="select * from table" >
On my webpage I could change the language of the contents by clicking an icon, when the icon was clicked a javascript command like var sURL = unescape(window.location.p athname); window.location.replace( sURL ); is performed. This all work ok.
Now I changed my accessdatasource and added : <SelectParameters> <asp:QueryStringParameter Name="Country" QueryStringField="C" />
</SelectParameters> </asp:AccessDataSource>
and in my codebehind I have :
If Not Page.IsPostBack Then
AccessDataSource1.SelectCo mmand = "SELECT * FROM table" 'where Country= " & Request.QueryString("C") & " order by id"
EmployeesGridView.Selected Index = 0
CustomersGridView_Selected IndexChang ed(sender, e)
End If
But when I do this now I get an error on :
Sub CustomersGridView_Selected IndexChang ed(ByVal sender As Object, ByVal e As EventArgs) Handles EmployeesGridView.Selected IndexChang ed
Dim row As GridViewRow = EmployeesGridView.Selected Row
...
saying :
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
What can this be and how can this be solved ??
<asp:AccessDataSource id="AccessDataSource1" DataFile="data\DBS.mdb" runat="server" selectcommand="select * from table" >
On my webpage I could change the language of the contents by clicking an icon, when the icon was clicked a javascript command like var sURL = unescape(window.location.p
Now I changed my accessdatasource and added : <SelectParameters> <asp:QueryStringParameter Name="Country" QueryStringField="C" />
</SelectParameters> </asp:AccessDataSource>
and in my codebehind I have :
If Not Page.IsPostBack Then
AccessDataSource1.SelectCo
EmployeesGridView.Selected
CustomersGridView_Selected
End If
But when I do this now I get an error on :
Sub CustomersGridView_Selected
Dim row As GridViewRow = EmployeesGridView.Selected
...
saying :
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
What can this be and how can this be solved ??
ASKER
This is the SelectedIndexChanged code :
Sub CustomersGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles EmployeesGridView.SelectedIndexChanged
Dim row As GridViewRow = EmployeesGridView.SelectedRow
Dim btnSelect As LinkButton = row.FindControl("btnSelect")
If btnSelect IsNot Nothing Then
Message.Text = "You selected " & btnSelect.Text & "."
Image1.ImageUrl = btnSelect.Attributes("img")
Dim Lang As String
Dim getCookie As HttpCookie
getCookie = Request.Cookies("Language")
Dim keyTemp As String
If getCookie.HasKeys Then
Dim valueCookie As New NameValueCollection(getCookie.Values)
For Each keyTemp In valueCookie.AllKeys
Response.Write(keyTemp & " : ")
Response.Write(getCookie.Values(keyTemp) & "<br>")
Next
Else
Response.Write(getCookie.Value)
lblLang.Text = getCookie.Value
Lang = getCookie.Value
If Lang = "L_Dutch" Then
PDF.NavigateUrl = row.Cells(1).Text
PDF.Text = row.Cells(1).Text 'btnSelect.Text
ElseIf Lang = "L_English" Then
PDF.NavigateUrl = row.Cells(2).Text
PDF.Text = row.Cells(2).Text 'btnSelect.Text
ElseIf Lang = "L_German" Then
PDF.NavigateUrl = row.Cells(3).Text
PDF.Text = row.Cells(3).Text 'btnSelect.Text
End If
End If
End Sub
ASKER
and this is the code of the gridview
<asp:GridView id="EmployeesGridView" runat="server" AutoGenerateColumns="False"
DataSourceid="AccessDataSource1" selectedindex="0"
onselectedindexchanged="CustomersGridView_SelectedIndexChanged"
onselectedindexchanging="CustomersGridView_SelectedIndexChanging"
ShowHeader="False" CellPadding="4" ForeColor="#333333" GridLines="None" Width="100%" >
When you have a select parameter defined then you should not use the select statement. Instead, set the value of the select parameter and call the Select() method of the datasource.
Do you get the error first time only or all the time?
Do you get the error first time only or all the time?
ASKER
yes but I do it now like (see code)
<asp:AccessDataSource id="AccessDataSource1" DataFile="data\nemotoDBS.mdb" runat="server" >
<SelectParameters> <asp:QueryStringParameter Name="Country" QueryStringField="C" /> </SelectParameters>
</asp:AccessDataSource>
aspx.VB :
AccessDataSource1.SelectCommand = "SELECT * FROM table " 'where Country= " & Request.QueryString("C") & " order by id"
EmployeesGridView.SelectedIndex = 0
CustomersGridView_SelectedIndexChanged(sender, e)
If you are doing this
AccessDataSource1.SelectCo mmand = "SELECT * FROM table " 'where Country= " & Request.QueryString("C") & " order by id"
You do not need this
<SelectParameters> <asp:QueryStringParameter Name="Country" QueryStringField="C" /> </SelectParameters>
AccessDataSource1.SelectCo
You do not need this
<SelectParameters> <asp:QueryStringParameter Name="Country" QueryStringField="C" /> </SelectParameters>
ASKER
If I remove that line it does not work at all.
Add a line here
AccessDataSource1.SelectCo mmand = "SELECT * FROM table " 'where Country= " & Request.QueryString("C") & " order by id"
AccessDataSource1.Select()
EmployeesGridView.Selected Index = 0
CustomersGridView_Selected IndexChang ed(sender, e)
AccessDataSource1.SelectCo
AccessDataSource1.Select()
EmployeesGridView.Selected
CustomersGridView_Selected
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could save a refresh by using the code i mentioned. Give it a try.
ASKER
that does not work with me, got the error : BC30455: Argument not specified for parameter 'arguments' of 'Public Function Select(arguments As System.Web.UI.DataSourceSe lectArgume nts) As System.Collections.IEnumer able'.
And I need to refresh it as a cookie changes and then some text changes based on that cookie, also the shown fields change as the language changes (based on that cookie)
And I need to refresh it as a cookie changes and then some text changes based on that cookie, also the shown fields change as the language changes (based on that cookie)
CustomersGridView_Selected
Mostly you use the value of "index" in it, which is null due to manual calling,
You can change it's code to not use the index, or make other function that doesn't use the index, and call it.
if you want more info you must provide us with it's code.