Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > error: Specified argument was out of the range of valid values. Parameter name: index

Reply
Thread Tools

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

 
 
Dave
Guest
Posts: n/a
 
      07-07-2006
Hi,

I want to change the color of two fields (a checkbox and a 'normal
stringfield') of my gridview depending of their value. The checkbox works
with the code below.
My question is: what do i have to take as object for the 'normal
stringfield'? I tried with 'textbox', with 'label' ... but each time i get
the error:
"Specified argument was out of the range of valid values. Parameter name:
index"

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
Dim cb As New CheckBox
Dim a As ???
cb = e.Row.Cells(6).Controls(0)
a = e.Row.Cells(5).Controls(0)
If cb.Checked Then
e.Row.Cells(0).BackColor = Drawing.Color.Red
e.Row.Cells(6).BackColor = Drawing.Color.Red
End If

if a.text (or matbe a.value) = "fat" then
e.Row.Cells(6).BackColor = Drawing.Color.Green
End If
End Sub

Thanks
Dave



 
Reply With Quote
 
 
 
 
Winista
Guest
Posts: n/a
 
      07-07-2006
In case of text, the cell itself has the text value set on it. You can skip
the part where you are looking for control at index 0.


"Dave" <vqsvd@sdvsd> wrote in message
news:%...
> Hi,
>
> I want to change the color of two fields (a checkbox and a 'normal
> stringfield') of my gridview depending of their value. The checkbox works
> with the code below.
> My question is: what do i have to take as object for the 'normal
> stringfield'? I tried with 'textbox', with 'label' ... but each time i get
> the error:
> "Specified argument was out of the range of valid values. Parameter name:
> index"
>
> Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
> System.Web.UI.WebControls.GridViewRowEventArgs) Handles
> GridView1.RowDataBound
> Dim cb As New CheckBox
> Dim a As ???
> cb = e.Row.Cells(6).Controls(0)
> a = e.Row.Cells(5).Controls(0)
> If cb.Checked Then
> e.Row.Cells(0).BackColor = Drawing.Color.Red
> e.Row.Cells(6).BackColor = Drawing.Color.Red
> End If
>
> if a.text (or matbe a.value) = "fat" then
> e.Row.Cells(6).BackColor = Drawing.Color.Green
> End If
> End Sub
>
> Thanks
> Dave
>
>
>



 
Reply With Quote
 
 
 
 
Winista
Guest
Posts: n/a
 
      07-08-2006
PArdon my VB I am not good at it..

You are trying to get the text in that cell. And then use that to check the
condition. You can do something like.

Dim aText As String


aText = e.Row.Cells(5).Text

if aText = "fat" then

Try it out...

"Dave" <vqsvd@sdvsd> wrote in message
news:...
> Thanks for replying,but forgive me if i don't understand what you mean ...
>
> I still don't know how to finish the line:
> dim as as ... (textbox ??)
> and when doing that, i still get the mentioned error ...
>
> If possible, can you show me the right code ...
> Thanks
>
> "Winista" <> schreef in bericht
> news:%...
>> In case of text, the cell itself has the text value set on it. You can
>> skip the part where you are looking for control at index 0.
>>
>>
>> "Dave" <vqsvd@sdvsd> wrote in message
>> news:%...
>>> Hi,
>>>
>>> I want to change the color of two fields (a checkbox and a 'normal
>>> stringfield') of my gridview depending of their value. The checkbox
>>> works
>>> with the code below.
>>> My question is: what do i have to take as object for the 'normal
>>> stringfield'? I tried with 'textbox', with 'label' ... but each time i
>>> get
>>> the error:
>>> "Specified argument was out of the range of valid values. Parameter
>>> name:
>>> index"
>>>
>>> Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
>>> System.Web.UI.WebControls.GridViewRowEventArgs) Handles
>>> GridView1.RowDataBound
>>> Dim cb As New CheckBox
>>> Dim a As ???
>>> cb = e.Row.Cells(6).Controls(0)
>>> a = e.Row.Cells(5).Controls(0)
>>> If cb.Checked Then
>>> e.Row.Cells(0).BackColor = Drawing.Color.Red
>>> e.Row.Cells(6).BackColor = Drawing.Color.Red
>>> End If
>>>
>>> if a.text (or matbe a.value) = "fat" then
>>> e.Row.Cells(6).BackColor = Drawing.Color.Green
>>> End If
>>> End Sub
>>>
>>> Thanks
>>> Dave
>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      07-08-2006
Thanks for replying,but forgive me if i don't understand what you mean ...

I still don't know how to finish the line:
dim as as ... (textbox ??)
and when doing that, i still get the mentioned error ...

If possible, can you show me the right code ...
Thanks

"Winista" <> schreef in bericht
news:%...
> In case of text, the cell itself has the text value set on it. You can
> skip the part where you are looking for control at index 0.
>
>
> "Dave" <vqsvd@sdvsd> wrote in message
> news:%...
>> Hi,
>>
>> I want to change the color of two fields (a checkbox and a 'normal
>> stringfield') of my gridview depending of their value. The checkbox works
>> with the code below.
>> My question is: what do i have to take as object for the 'normal
>> stringfield'? I tried with 'textbox', with 'label' ... but each time i
>> get
>> the error:
>> "Specified argument was out of the range of valid values. Parameter name:
>> index"
>>
>> Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
>> System.Web.UI.WebControls.GridViewRowEventArgs) Handles
>> GridView1.RowDataBound
>> Dim cb As New CheckBox
>> Dim a As ???
>> cb = e.Row.Cells(6).Controls(0)
>> a = e.Row.Cells(5).Controls(0)
>> If cb.Checked Then
>> e.Row.Cells(0).BackColor = Drawing.Color.Red
>> e.Row.Cells(6).BackColor = Drawing.Color.Red
>> End If
>>
>> if a.text (or matbe a.value) = "fat" then
>> e.Row.Cells(6).BackColor = Drawing.Color.Green
>> End If
>> End Sub
>>
>> Thanks
>> Dave
>>
>>
>>

>
>



 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      07-08-2006
Thanks, it works now ...

But i still don't undertsand why this statement works: (independantely of
property 'text')
Dim cb As New CheckBox
cb = e.Row.Cells(6).Controls(0)

but not this: (gives mentioned error)
Dim a As new textbox
a = e.Row.Cells(5).Controls(0)

Thansk again

"Winista" <> schreef in bericht
news:...
> PArdon my VB I am not good at it..
>
> You are trying to get the text in that cell. And then use that to check
> the condition. You can do something like.
>
> Dim aText As String
>
>
> aText = e.Row.Cells(5).Text
>
> if aText = "fat" then
>
> Try it out...
>
> "Dave" <vqsvd@sdvsd> wrote in message
> news:...
>> Thanks for replying,but forgive me if i don't understand what you mean
>> ...
>>
>> I still don't know how to finish the line:
>> dim as as ... (textbox ??)
>> and when doing that, i still get the mentioned error ...
>>
>> If possible, can you show me the right code ...
>> Thanks
>>
>> "Winista" <> schreef in bericht
>> news:%...
>>> In case of text, the cell itself has the text value set on it. You can
>>> skip the part where you are looking for control at index 0.
>>>
>>>
>>> "Dave" <vqsvd@sdvsd> wrote in message
>>> news:%...
>>>> Hi,
>>>>
>>>> I want to change the color of two fields (a checkbox and a 'normal
>>>> stringfield') of my gridview depending of their value. The checkbox
>>>> works
>>>> with the code below.
>>>> My question is: what do i have to take as object for the 'normal
>>>> stringfield'? I tried with 'textbox', with 'label' ... but each time i
>>>> get
>>>> the error:
>>>> "Specified argument was out of the range of valid values. Parameter
>>>> name:
>>>> index"
>>>>
>>>> Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
>>>> System.Web.UI.WebControls.GridViewRowEventArgs) Handles
>>>> GridView1.RowDataBound
>>>> Dim cb As New CheckBox
>>>> Dim a As ???
>>>> cb = e.Row.Cells(6).Controls(0)
>>>> a = e.Row.Cells(5).Controls(0)
>>>> If cb.Checked Then
>>>> e.Row.Cells(0).BackColor = Drawing.Color.Red
>>>> e.Row.Cells(6).BackColor = Drawing.Color.Red
>>>> End If
>>>>
>>>> if a.text (or matbe a.value) = "fat" then
>>>> e.Row.Cells(6).BackColor = Drawing.Color.Green
>>>> End If
>>>> End Sub
>>>>
>>>> Thanks
>>>> Dave
>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Jesse Houwing
Guest
Posts: n/a
 
      07-08-2006
Dave wrote:
> Thanks, it works now ...
>
> But i still don't undertsand why this statement works: (independantely of
> property 'text')
> Dim cb As New CheckBox
> cb = e.Row.Cells(6).Controls(0)
>
> but not this: (gives mentioned error)
> Dim a As new textbox
> a = e.Row.Cells(5).Controls(0)
>


I guess it would be because Cells(5) contains no controls, so
Controls(0) is out of range.

Jesse

> Thansk again
>
> "Winista" <> schreef in bericht
> news:...
>> PArdon my VB I am not good at it..
>>
>> You are trying to get the text in that cell. And then use that to check
>> the condition. You can do something like.
>>
>> Dim aText As String
>>
>>
>> aText = e.Row.Cells(5).Text
>>
>> if aText = "fat" then
>>
>> Try it out...
>>
>> "Dave" <vqsvd@sdvsd> wrote in message
>> news:...
>>> Thanks for replying,but forgive me if i don't understand what you mean
>>> ...
>>>
>>> I still don't know how to finish the line:
>>> dim as as ... (textbox ??)
>>> and when doing that, i still get the mentioned error ...
>>>
>>> If possible, can you show me the right code ...
>>> Thanks
>>>
>>> "Winista" <> schreef in bericht
>>> news:%...
>>>> In case of text, the cell itself has the text value set on it. You can
>>>> skip the part where you are looking for control at index 0.
>>>>
>>>>
>>>> "Dave" <vqsvd@sdvsd> wrote in message
>>>> news:%...
>>>>> Hi,
>>>>>
>>>>> I want to change the color of two fields (a checkbox and a 'normal
>>>>> stringfield') of my gridview depending of their value. The checkbox
>>>>> works
>>>>> with the code below.
>>>>> My question is: what do i have to take as object for the 'normal
>>>>> stringfield'? I tried with 'textbox', with 'label' ... but each time i
>>>>> get
>>>>> the error:
>>>>> "Specified argument was out of the range of valid values. Parameter
>>>>> name:
>>>>> index"
>>>>>
>>>>> Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
>>>>> System.Web.UI.WebControls.GridViewRowEventArgs) Handles
>>>>> GridView1.RowDataBound
>>>>> Dim cb As New CheckBox
>>>>> Dim a As ???
>>>>> cb = e.Row.Cells(6).Controls(0)
>>>>> a = e.Row.Cells(5).Controls(0)
>>>>> If cb.Checked Then
>>>>> e.Row.Cells(0).BackColor = Drawing.Color.Red
>>>>> e.Row.Cells(6).BackColor = Drawing.Color.Red
>>>>> End If
>>>>>
>>>>> if a.text (or matbe a.value) = "fat" then
>>>>> e.Row.Cells(6).BackColor = Drawing.Color.Green
>>>>> End If
>>>>> End Sub
>>>>>
>>>>> Thanks
>>>>> Dave
>>>>>
>>>>>
>>>>>
>>>>
>>>

>>

>
>

 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      07-08-2006
Hi Jesse,

The gridview contains 7 fields (i can see them on screen). The last is a
checkbox and the first six are textfield.
So e.Row.Cells(6).Controls(0) is the checkbox, but why are
e.Row.Cells(0).Controls(0) till e.Row.Cells(5).Controls(0) out of range ???

Maybe are these texrfield not 'textbox'? But then, what are they? How can i
know that?
Thanks


"Jesse Houwing" <> schreef in bericht
news:%23vit%...
> Dave wrote:
>> Thanks, it works now ...
>>
>> But i still don't undertsand why this statement works: (independantely of
>> property 'text')
>> Dim cb As New CheckBox
>> cb = e.Row.Cells(6).Controls(0)
>>
>> but not this: (gives mentioned error)
>> Dim a As new textbox
>> a = e.Row.Cells(5).Controls(0)
>>

>
> I guess it would be because Cells(5) contains no controls, so Controls(0)
> is out of range.
>
> Jesse
>
>> Thansk again
>>
>> "Winista" <> schreef in bericht
>> news:...
>>> PArdon my VB I am not good at it..
>>>
>>> You are trying to get the text in that cell. And then use that to check
>>> the condition. You can do something like.
>>>
>>> Dim aText As String
>>>
>>>
>>> aText = e.Row.Cells(5).Text
>>>
>>> if aText = "fat" then
>>>
>>> Try it out...
>>>
>>> "Dave" <vqsvd@sdvsd> wrote in message
>>> news:...
>>>> Thanks for replying,but forgive me if i don't understand what you mean
>>>> ...
>>>>
>>>> I still don't know how to finish the line:
>>>> dim as as ... (textbox ??)
>>>> and when doing that, i still get the mentioned error ...
>>>>
>>>> If possible, can you show me the right code ...
>>>> Thanks
>>>>
>>>> "Winista" <> schreef in bericht
>>>> news:%...
>>>>> In case of text, the cell itself has the text value set on it. You can
>>>>> skip the part where you are looking for control at index 0.
>>>>>
>>>>>
>>>>> "Dave" <vqsvd@sdvsd> wrote in message
>>>>> news:%...
>>>>>> Hi,
>>>>>>
>>>>>> I want to change the color of two fields (a checkbox and a 'normal
>>>>>> stringfield') of my gridview depending of their value. The checkbox
>>>>>> works
>>>>>> with the code below.
>>>>>> My question is: what do i have to take as object for the 'normal
>>>>>> stringfield'? I tried with 'textbox', with 'label' ... but each time
>>>>>> i get
>>>>>> the error:
>>>>>> "Specified argument was out of the range of valid values. Parameter
>>>>>> name:
>>>>>> index"
>>>>>>
>>>>>> Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e
>>>>>> As
>>>>>> System.Web.UI.WebControls.GridViewRowEventArgs) Handles
>>>>>> GridView1.RowDataBound
>>>>>> Dim cb As New CheckBox
>>>>>> Dim a As ???
>>>>>> cb = e.Row.Cells(6).Controls(0)
>>>>>> a = e.Row.Cells(5).Controls(0)
>>>>>> If cb.Checked Then
>>>>>> e.Row.Cells(0).BackColor = Drawing.Color.Red
>>>>>> e.Row.Cells(6).BackColor = Drawing.Color.Red
>>>>>> End If
>>>>>>
>>>>>> if a.text (or matbe a.value) = "fat" then
>>>>>> e.Row.Cells(6).BackColor = Drawing.Color.Green
>>>>>> End If
>>>>>> End Sub
>>>>>>
>>>>>> Thanks
>>>>>> Dave
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>

>>


 
Reply With Quote
 
Jesse Houwing
Guest
Posts: n/a
 
      07-08-2006
Dave wrote:
> Hi Jesse,
>
> The gridview contains 7 fields (i can see them on screen). The last is a
> checkbox and the first six are textfield.
> So e.Row.Cells(6).Controls(0) is the checkbox, but why are
> e.Row.Cells(0).Controls(0) till e.Row.Cells(5).Controls(0) out of range ???
>
> Maybe are these texrfield not 'textbox'? But then, what are they? How can i
> know that?


Maybe they're just plain HTML input boxes. Or other plain text. Can you
post the corresponding code from the ASPX?

Jesse
 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      07-09-2006
Hi,

Here below is the ASPX code:
as you can see, they are 6 'Boundfield' and 1 checkfield, but when doing
this:
dim c as new BoundField
c=e.Row.Cells(0).Controls(0)

i get the error:"type 'System.Web.UI.Control' cannot be converted to
'System.Web.UI.WebControls.BoundField'.

I also tried with"Htmlinputtext", "tablecell" ...

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=c:\my.mdb"
ProviderName="System.Data.OleDb" SelectCommand="SELECT fld1,
fld2,fld3,fld4,fld5,fld6, fld7FROM mytable"></asp:SqlDataSource>

<asp:GridView ID="GridView1" runat="server"
<Columns>
<asp:BoundField DataField="fld1"
HeaderText="Computer"
SortExpression="fld1" />
<asp:BoundField DataField="fld2"
HeaderText="Lok"
SortExpression="fld2" />
<asp:BoundField DataField="fld3"
HeaderText="Oms"
SortExpression="fld3" />
<asp:BoundField DataField="fld4"
HeaderText="Type"
SortExpression="fld4" />
<asp:BoundField DataField="fld5"
HeaderText="Soft"
SortExpression="fld5" />
<asp:BoundField DataField="fld6
HeaderText="Thin"
SortExpression="fld6" />
<asp:CheckBoxField DataField="fld7"
HeaderText="Def"
SortExpression="fld7" />
</Columns>
</asp:GridView>


"Jesse Houwing" <> schreef in bericht
news:...
> Dave wrote:
>> Hi Jesse,
>>
>> The gridview contains 7 fields (i can see them on screen). The last is a
>> checkbox and the first six are textfield.
>> So e.Row.Cells(6).Controls(0) is the checkbox, but why are
>> e.Row.Cells(0).Controls(0) till e.Row.Cells(5).Controls(0) out of range
>> ???
>>
>> Maybe are these texrfield not 'textbox'? But then, what are they? How can
>> i know that?

>
> Maybe they're just plain HTML input boxes. Or other plain text. Can you
> post the corresponding code from the ASPX?
>
> Jesse



 
Reply With Quote
 
Jesse Houwing
Guest
Posts: n/a
 
      07-09-2006
* Dave wrote, On 9-7-2006 10:12:
> Hi,
>
> Here below is the ASPX code:
> as you can see, they are 6 'Boundfield' and 1 checkfield, but when doing
> this:
> dim c as new BoundField
> c=e.Row.Cells(0).Controls(0)
>
> i get the error:"type 'System.Web.UI.Control' cannot be converted to
> 'System.Web.UI.WebControls.BoundField'.
>
> I also tried with"Htmlinputtext", "tablecell" ...
>
> <asp:SqlDataSource ID="SqlDataSource1" runat="server"
> ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=c:\my.mdb"
> ProviderName="System.Data.OleDb" SelectCommand="SELECT fld1,
> fld2,fld3,fld4,fld5,fld6, fld7FROM mytable"></asp:SqlDataSource>
>
> <asp:GridView ID="GridView1" runat="server"
> <Columns>
> <asp:BoundField DataField="fld1"
> HeaderText="Computer"
> SortExpression="fld1" />
> <asp:BoundField DataField="fld2"
> HeaderText="Lok"
> SortExpression="fld2" />
> <asp:BoundField DataField="fld3"
> HeaderText="Oms"
> SortExpression="fld3" />
> <asp:BoundField DataField="fld4"
> HeaderText="Type"
> SortExpression="fld4" />
> <asp:BoundField DataField="fld5"
> HeaderText="Soft"
> SortExpression="fld5" />
> <asp:BoundField DataField="fld6
> HeaderText="Thin"
> SortExpression="fld6" />
> <asp:CheckBoxField DataField="fld7"
> HeaderText="Def"
> SortExpression="fld7" />
> </Columns>
> </asp:GridView>
>
>
> "Jesse Houwing" <> schreef in bericht
> news:...
>> Dave wrote:
>>> Hi Jesse,
>>>
>>> The gridview contains 7 fields (i can see them on screen). The last is a
>>> checkbox and the first six are textfield.
>>> So e.Row.Cells(6).Controls(0) is the checkbox, but why are
>>> e.Row.Cells(0).Controls(0) till e.Row.Cells(5).Controls(0) out of range
>>> ???
>>>
>>> Maybe are these texrfield not 'textbox'? But then, what are they? How can
>>> i know that?

>> Maybe they're just plain HTML input boxes. Or other plain text. Can you
>> post the corresponding code from the ASPX?
>>
>> Jesse

>
>


The last field contains a checkbox which will be represented as a
control, the others are just bound text which will not create a control.
To get to that text from your code-behind you should use

e.Row.Cells(0).Text

A control will only be added if the row is in edit mode (then it wil
contain a textbox control).

Should you always want a conrtol in there for some reason, use a
templatecolumn and then you can put in any controls you'd want.

Jesse
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: Specified argument was out of the range of valid values.Parameter name Index. siha General Computer Support 0 12-07-2010 01:51 AM
Specified argument was out of the range of valid values. Parameter Dave ASP .Net 0 09-24-2010 04:18 PM
Specified argument was out of the range of valid values.Parameter Chapi ASP .Net 2 05-26-2008 05:38 PM
Specified argument was out of the range of valid values. Parameter name: value? darrel ASP .Net 0 08-14-2006 10:32 PM
Specified argument was out of the range of valid values. Parameter name: 0 Todd Perkins ASP .Net 0 09-15-2004 07:46 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57