473,378 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Cell(0) and Control(0)

Hi,

I keep getting the following error in my code:

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index

I presume it is because I have the wrong control number but am not 100% sure! How do I work this out?

Thanks

...::CODE::..
Sub DGPages_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
' First, make sure we're NOT dealing with a Header or Footer row
If e.Item.ItemType <> ListItemType.Header And _
e.Item.ItemType <> ListItemType.Footer Then
'Now, reference the LinkButton control that the Delete ButtonColumn
'has been rendered to
Dim deleteButton As LinkButton = e.Item.Cells(0).Controls(0) ' Error

'We can now add the onclick event handler
deleteButton.Attributes("onclick") = "javascript:return " & _
"confirm('Are you sure you want to delete Page #" & _
DataBinder.Eval(e.Item.DataItem, "ID") & "?')"
End If
End Sub

...::
<asp:datagrid id="DGPages" runat="server"
HeaderStyle-Font-Bold="True"
HeaderStyle-HorizontalAlign="Center"
HeaderStyle-ForeColor="White"
HeaderStyle-BackColor="Black"

EditItemStyle-BackColor="#eeeeee"

CellPadding="4"
Width="90%"
AutoGenerateColumns="False"

DataKeyField="pageID"
OnItemDataBound="DGPages_ItemDataBound"
OnEditCommand="DGPages_Edit"
OnUpdateCommand="DGPages_Update"
OnCancelCommand="DGPages_Cancel"
OnDeleteCommand="DGPages_Delete">

<Columns>
<asp:BoundColumn DataField="pageID" ReadOnly="True" HeaderText="ID">
<ItemStyle CssClass="txtArea"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="modificationDate" HeaderText="Date Modified" DataFormatString="{0:MM/dd/yyyy}">
<ItemStyle CssClass="txtArea"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="description" HeaderText="Description">
<ItemStyle CssClass="txtArea"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="header" HeaderText="Title">
<ItemStyle CssClass="txtArea"></ItemStyle>
</asp:BoundColumn>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete" ButtonType="LinkButton"></asp:ButtonColumn>
</Columns>
</asp:datagrid>
Nov 18 '05 #1
3 2337
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:B6**********************************@microsof t.com...
Hi,

I keep getting the following error in my code:

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index
I presume it is because I have the wrong control number but am not 100%

sure! How do I work this out?

Didn't I answer this one already?

You either have no cells, or you have at least one cell and no controls in
it. Try doing a Response.Write(e.Item.Cells(0).Controls.Count.ToSt ring())
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #2
Because of using BoundColumn for your first column actually you don't have
controls in it - you have only text there
you can check it by debuging your application and check
e.Item.Cells(0).Controls.Count

also as i see from yuor code the LinkButton Control is not in the first but
in the last column, so may be you have to use

e.Item.Cells(5).Controls(1), but you have to check if the LinkButton is the
second control

Regards
Martin

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:B6**********************************@microsof t.com...
Hi,

I keep getting the following error in my code:

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index
I presume it is because I have the wrong control number but am not 100% sure! How do I work this out?
Thanks

..::CODE::..
Sub DGPages_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) ' First, make sure we're NOT dealing with a Header or Footer row
If e.Item.ItemType <> ListItemType.Header And _
e.Item.ItemType <> ListItemType.Footer Then
'Now, reference the LinkButton control that the Delete ButtonColumn 'has been rendered to
Dim deleteButton As LinkButton = e.Item.Cells(0).Controls(0) ' Error
'We can now add the onclick event handler
deleteButton.Attributes("onclick") = "javascript:return " & _
"confirm('Are you sure you want to delete Page #" & _ DataBinder.Eval(e.Item.DataItem, "ID") & "?')"
End If
End Sub

..::
<asp:datagrid id="DGPages" runat="server"
HeaderStyle-Font-Bold="True"
HeaderStyle-HorizontalAlign="Center"
HeaderStyle-ForeColor="White"
HeaderStyle-BackColor="Black"

EditItemStyle-BackColor="#eeeeee"

CellPadding="4"
Width="90%"
AutoGenerateColumns="False"

DataKeyField="pageID"
OnItemDataBound="DGPages_ItemDataBound"
OnEditCommand="DGPages_Edit"
OnUpdateCommand="DGPages_Update"
OnCancelCommand="DGPages_Cancel"
OnDeleteCommand="DGPages_Delete">

<Columns>
<asp:BoundColumn DataField="pageID" ReadOnly="True" HeaderText="ID">
<ItemStyle CssClass="txtArea"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="modificationDate" HeaderText="Date Modified" DataFormatString="{0:MM/dd/yyyy}"> <ItemStyle CssClass="txtArea"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="description" HeaderText="Description">
<ItemStyle CssClass="txtArea"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="header" HeaderText="Title">
<ItemStyle CssClass="txtArea"></ItemStyle>
</asp:BoundColumn>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn> <asp:ButtonColumn Text="Delete" CommandName="Delete" ButtonType="LinkButton"></asp:ButtonColumn> </Columns>
</asp:datagrid>

Nov 18 '05 #3
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:A6**********************************@microsof t.com...
Thanks John!

Sorry I miss understood your first reply! I did the response.write and it returned 00! Sorry I'm new to asp.net what sort of response am I looking for????

There is data in the pageID DataField so why wouldn't it work? Perhaps

pointing at the wrong cell and wrong control!

Tim, 0 showed what I expected, that there are no controls in Cell 0. Perhaps
you are mistaken about which Cell your controls are in? Try setting a
breakpoint in the debugger and examining e.Item, or else try adding some
code like this instead of the Response.Write (untested! gotta run to a job
interview):

Dim cell As TableCell
Dim ctl As Control
Dim i As Integer
Dim j As Integer

For i = 0 to e.Item.Cells.Count -1
cell = e.Item.Cells(i)

If cell.Controls.Count = 0 Then
Page.Trace.Write(String.Format("No controls in cell {0}", i))
Else
Page.Trace.Write(String.Format("{0} controls in cell
{1}",cell.Controls.Count , i))
For j = 0 to cell.Controls.Count - 1
ctl = cell.Controls(j)

Page.Trace.Write(String.Format("Control {0} in cell {1} is {2}",
j, i, cell.Controls(j)))
Next j
End If
Next i

--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mefloyd | last post by:
Hello, I'd like to outline the current cell in an MSFlexGrid control with a certain color and line thickness. I thought of putting a shape control on the form and positioning it over the cell,...
3
by: David Whitney | last post by:
All: I have a control that renders a table. As the table is rendered, each row in the table is constructed by creating a run-time (dynamic) object that is derived from an HtmlTableRow. The row...
4
by: simon | last post by:
which data control allows me to use a cell doubleClick event? I have time cells (something like Outlook calendar) and when user double click on one cell I would like to redirect to other window...
6
by: William Sullivan | last post by:
I want to fill a cell in a table with a control. Lets say the control is a listbox--something that you'd think would easily fill a cell, which would be a good thing. So I create the table and...
3
by: gh | last post by:
I have a HTML Table with 1 row and 1 column. I have a control I want to add to the cell at runtime based on a condition. I can get the control added by creating a row and cell and using the code...
2
by: GV | last post by:
Hi all, I created 2 label controls and add them to a table cell the first one is fine left justified but i want to right justify the 2nd label control to the right of the cell? How to you...
0
by: bemanian | last post by:
Hi, This is a simple DataGridView in a windows form which contains a number of other controls as buttons, text boxes and so on. The problem is when the data grid cell editing is conducted via...
2
by: Jeff User | last post by:
Hi Using C# in vs2003 to develop web stuff. I created a "Web user control" (.ascx and ascx.cs files), that contains a few simple (for starters) html items. I can place the item on...
1
by: DaveyP | last post by:
I have a user control (called data_dictionary) which I need to add into the header text of a datagrid. I'm doing this by adding the control in the RowCreated event as follows: dds_descriptions...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.