By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

Cell(0) and Control(0)

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.