Hi,
I have a datagrid in my application that has a Template Column with a
radiobutton. After selecting the item in the datagrid and the submit button,
the program executes getSelectedItem (). See below. This works fine except
when there is only one row in the datagrid. Then I get the Index out of
bounds error.
Has anyone seen this before?
Dave
Private Function GetSelectedItem s(ByVal grdlst As DataGrid) As String
Dim rowCount As Integer = 0
Dim gridSelections As StringBuilder = New StringBuilder
Try
Dim oDataGridItem As DataGridItem
For Each oDataGridItem In grdlst.Items
Dim rdoSelected As RadioButton =
CType(oDataGrid Item.Cells(0).C ontrols(1), RadioButton)
If rdoSelected.Che cked = True Then
rowCount += 1
gridSelections. AppendFormat("{ 0}~",
grdlst.DataKeys (oDataGridItem. ItemIndex).ToSt ring())
End If
Next
Catch ex As Exception
lblMessage.Text = "Error finding selected row; " & ex.Message
End Try
If rowCount > 0 Then
'Remove the last separation symbol
'gridSelections .Remove(gridSel ections.Length - 1, 1)
Return (gridSelections .ToString)
Else
Return ("")
End If
End Function 2 1665
Just wondering if your problem has to do with the For Each loop trying to
find a checkbox inside header and footer items?
A fix would be to check that you are only looking inside
ListItemType.Al ternatingItem and ListItemType.It em types
Ken
MVP [ASP.NET]
"dw****@company abc.com" <dw************ *****@discussio ns.microsoft.co m>
wrote in message news:39******** *************** ***********@mic rosoft.com... Hi,
I have a datagrid in my application that has a Template Column with a radiobutton. After selecting the item in the datagrid and the submit button, the program executes getSelectedItem (). See below. This works fine except when there is only one row in the datagrid. Then I get the Index out of bounds error.
Has anyone seen this before?
Dave Private Function GetSelectedItem s(ByVal grdlst As DataGrid) As String Dim rowCount As Integer = 0 Dim gridSelections As StringBuilder = New StringBuilder Try Dim oDataGridItem As DataGridItem For Each oDataGridItem In grdlst.Items Dim rdoSelected As RadioButton = CType(oDataGrid Item.Cells(0).C ontrols(1), RadioButton)
If rdoSelected.Che cked = True Then rowCount += 1 gridSelections. AppendFormat("{ 0}~", grdlst.DataKeys (oDataGridItem. ItemIndex).ToSt ring()) End If Next
Catch ex As Exception lblMessage.Text = "Error finding selected row; " & ex.Message End Try
If rowCount > 0 Then 'Remove the last separation symbol 'gridSelections .Remove(gridSel ections.Length - 1, 1) Return (gridSelections .ToString) Else Return ("") End If End Function
Ken,
Thanks for the response. I found the problem. I didn't define a DataKey
for the Datagrid. DataKeys are required to pick up the selected row. So my
code looks like the following now:
dvPromote = New DataView(dtProm ote)
dgRequests.Data Source = dvPromote
dgRequests.Data KeyField = "Tran_ID"
dgRequests.Data Bind()
I didn't show this code before, but the dgRequests.Data KeyField entry was
missing.
Thanks again for your help.
Dave
"Ken Cox [Microsoft MVP]" wrote: Just wondering if your problem has to do with the For Each loop trying to find a checkbox inside header and footer items?
A fix would be to check that you are only looking inside ListItemType.Al ternatingItem and ListItemType.It em types
Ken MVP [ASP.NET] "dw****@company abc.com" <dw************ *****@discussio ns.microsoft.co m> wrote in message news:39******** *************** ***********@mic rosoft.com... Hi,
I have a datagrid in my application that has a Template Column with a radiobutton. After selecting the item in the datagrid and the submit button, the program executes getSelectedItem (). See below. This works fine except when there is only one row in the datagrid. Then I get the Index out of bounds error.
Has anyone seen this before?
Dave Private Function GetSelectedItem s(ByVal grdlst As DataGrid) As String Dim rowCount As Integer = 0 Dim gridSelections As StringBuilder = New StringBuilder Try Dim oDataGridItem As DataGridItem For Each oDataGridItem In grdlst.Items Dim rdoSelected As RadioButton = CType(oDataGrid Item.Cells(0).C ontrols(1), RadioButton)
If rdoSelected.Che cked = True Then rowCount += 1 gridSelections. AppendFormat("{ 0}~", grdlst.DataKeys (oDataGridItem. ItemIndex).ToSt ring()) End If Next
Catch ex As Exception lblMessage.Text = "Error finding selected row; " & ex.Message End Try
If rowCount > 0 Then 'Remove the last separation symbol 'gridSelections .Remove(gridSel ections.Length - 1, 1) Return (gridSelections .ToString) Else Return ("") End If End Function
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eugene |
last post by:
Hello all,
I've been trying to figure this out for a few days now, and still have
no clue what's going on...
I have a few related tables in MS Access (Clients, Cars, Sales), and a
datagrid, binded to dataview.
Here's a catch - whenever I select a client, and then find a car which
belongs to this client, and click on empty space in datagrid (that is
in gray area below rows) - I get "Index was outside the bounds of the
array" error......
|
by: Joe |
last post by:
This is a weird problem.
when doing trying to add a tabpage to a tabcontrol I get an error:
Index was outside the bounds of the array.
Now this only happens when I call a function from within a callback for an
Async webmethod call.
My guess is that it has something to do with the threads not being in sync
yet.
|
by: scotthutchinson |
last post by:
I have a .NET Remoting object hosted in IIS6 on Windows Server 2003
(happens before and after installing SP1) at an endpoint (ASP.NET
application virtual folder) named "CompanyXYZReporting". The remoted
object is called several times every day and works perfectly except
every 2-3 weeks when we call the remoted object, the response returns
the error shown below. Does anyone have any clues how to resolve this
problem?
Server Error in...
|
by: Denis C |
last post by:
Hi there,
I'm trying to convert part of a byte array into a series
of fixed length strings but half way through the for loop
I get an error that I'm accessing outside the buffer
bounds.
The error:
An unhandled exception of
|
by: Antoine |
last post by:
Herfried and Cor:-
I used tracing and actually tracked down the code that was causing the
problem most likely. I wonder if you wanted to comment on it.
Also I wonder if there is a better way of testing if there is data than
testing the length of the xml string I used as stringreader to create the
dataset, but thats a side issue.
I think I tried isdbnull and is nothing and stuff like that and they cause
| |
by: Cammie Watson |
last post by:
Hi there,
We have a web application written in asp.net (1.1). I'm not going to go
into too much detail but we use a DLL to communicate with the database and
also a couple of webservices. When we deployed version 1, everything
deployed OK on our webserver. We deployed the application and 1 webservice
under default web site, the other webservice (3rd party supplied) is on
another server and services many other application in our...
|
by: writebrent |
last post by:
I wrote a little interface for users to post data to a website. On
their local machines, it produces CSV from an Excel spreadsheet, then
posts it to the site. In some cases, the CSV will contain ampersands.
For example,
abc,American & British Company,1,4.34,5
ded,Dog Eat Dog,2,6.3,5.766
The code on the site is pretty standard: it loops through an array of
lines from the CSV split on line ends, and then loops through another
|
by: =?Utf-8?B?UmljaA==?= |
last post by:
Greetings,
Dim dr as datarow
dr = ds.Table("tbl1").Select("RowID = " & txt1.Text")
If dr("RowID").ToString.Equals("123") Then...
if the RowID in txt1.Text does not exist in "tbl1" then I get the index out
of bounds error -- dr did not get a row - a row with that RowID does not
exist. How can I trap for this error?
|
by: weird0 |
last post by:
I have no idea why this error this is coming and how can i fix it?
Can anyone please help me with it..............?
public static class BillManager
{
private static Object ExecuteSP(Object argArray)
{
SqlCommand sqlcmd = new SqlCommand();
SqlConnection sqlconnection1 = new SqlConnection();
sqlcmd.Connection = sqlconnection1;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |