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

Getting data out of the Repeater Web Control

P: n/a
Hello -

I'm using a Repeater control to render information in a very customized
grid-like table. The Repeater control is binded to a DataSet with several
records of information. Within the Repeater control, I've placed
DropDownLists and CheckBoxes.

When the user has updated the information, he/he clicks the submit button
which is outside the scope of the Repeater control.

What i need to do, is read each of the values from DropDownLists and
CheckBoxes and save these into the database. How can i read these controls
from code-behind?

I was thinking of using:

foreach (Control ctr in Page.Controls)
{
if (ctr is DropDownList)
{
// do something
}
}

However, i cannot find the repeater control. Any ideas how to do this?

Thanks,
Nov 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
You can loop through the repeater Items collection, find the ddls and
checkboxes with the item's FindControl method, get the values, set them in
the dataset table and at the end call the Update method of the data adapter
that links the dataset to the database.

Eliyahu

"charliewest" <ch*********@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
Hello -

I'm using a Repeater control to render information in a very customized
grid-like table. The Repeater control is binded to a DataSet with several
records of information. Within the Repeater control, I've placed
DropDownLists and CheckBoxes.

When the user has updated the information, he/he clicks the submit button
which is outside the scope of the Repeater control.

What i need to do, is read each of the values from DropDownLists and
CheckBoxes and save these into the database. How can i read these controls
from code-behind?

I was thinking of using:

foreach (Control ctr in Page.Controls)
{
if (ctr is DropDownList)
{
// do something
}
}

However, i cannot find the repeater control. Any ideas how to do this?

Thanks,

Nov 19 '05 #2

P: n/a
Thanks, but in my scenario, this is not possible. My custom-grid created with
the repeater controls, comprises, several different DataSets as well as
unique info from constants, session vars, etc... Hence, i need to be able to
loop through the controls collection. Any ideas?

Thanks again,

"Eliyahu Goldin" wrote:
You can loop through the repeater Items collection, find the ddls and
checkboxes with the item's FindControl method, get the values, set them in
the dataset table and at the end call the Update method of the data adapter
that links the dataset to the database.

Eliyahu

"charliewest" <ch*********@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
Hello -

I'm using a Repeater control to render information in a very customized
grid-like table. The Repeater control is binded to a DataSet with several
records of information. Within the Repeater control, I've placed
DropDownLists and CheckBoxes.

When the user has updated the information, he/he clicks the submit button
which is outside the scope of the Repeater control.

What i need to do, is read each of the values from DropDownLists and
CheckBoxes and save these into the database. How can i read these controls
from code-behind?

I was thinking of using:

foreach (Control ctr in Page.Controls)
{
if (ctr is DropDownList)
{
// do something
}
}

However, i cannot find the repeater control. Any ideas how to do this?

Thanks,


Nov 19 '05 #3

P: n/a
Your original question refers to just one repeater. Do you mean you have
nested repeaters? You can always get to any single one of them and then loop
through its items.

Eliyahu

"charliewest" <ch*********@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
Thanks, but in my scenario, this is not possible. My custom-grid created with the repeater controls, comprises, several different DataSets as well as
unique info from constants, session vars, etc... Hence, i need to be able to loop through the controls collection. Any ideas?

Thanks again,

"Eliyahu Goldin" wrote:
You can loop through the repeater Items collection, find the ddls and
checkboxes with the item's FindControl method, get the values, set them in the dataset table and at the end call the Update method of the data adapter that links the dataset to the database.

Eliyahu

"charliewest" <ch*********@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
Hello -

I'm using a Repeater control to render information in a very customized grid-like table. The Repeater control is binded to a DataSet with several records of information. Within the Repeater control, I've placed
DropDownLists and CheckBoxes.

When the user has updated the information, he/he clicks the submit button which is outside the scope of the Repeater control.

What i need to do, is read each of the values from DropDownLists and
CheckBoxes and save these into the database. How can i read these controls from code-behind?

I was thinking of using:

foreach (Control ctr in Page.Controls)
{
if (ctr is DropDownList)
{
// do something
}
}

However, i cannot find the repeater control. Any ideas how to do this?

Thanks,


Nov 19 '05 #4

P: n/a
First, thanks Eliyahu for your help.

I don't have nested repeaters, i am only using one. I do have other nested
controls, specifically the DropDownList and CheckBox. The Submit Button is
not part of the Repeater control.

I am assuming that you suggest taht i use the Repeater.Controls collection
to loop?

"Eliyahu Goldin" wrote:
Your original question refers to just one repeater. Do you mean you have
nested repeaters? You can always get to any single one of them and then loop
through its items.

Eliyahu

"charliewest" <ch*********@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
Thanks, but in my scenario, this is not possible. My custom-grid created

with
the repeater controls, comprises, several different DataSets as well as
unique info from constants, session vars, etc... Hence, i need to be able

to
loop through the controls collection. Any ideas?

Thanks again,

"Eliyahu Goldin" wrote:
You can loop through the repeater Items collection, find the ddls and
checkboxes with the item's FindControl method, get the values, set them in the dataset table and at the end call the Update method of the data adapter that links the dataset to the database.

Eliyahu

"charliewest" <ch*********@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
> Hello -
>
> I'm using a Repeater control to render information in a very customized > grid-like table. The Repeater control is binded to a DataSet with several > records of information. Within the Repeater control, I've placed
> DropDownLists and CheckBoxes.
>
> When the user has updated the information, he/he clicks the submit button > which is outside the scope of the Repeater control.
>
> What i need to do, is read each of the values from DropDownLists and
> CheckBoxes and save these into the database. How can i read these controls > from code-behind?
>
> I was thinking of using:
>
> foreach (Control ctr in Page.Controls)
> {
> if (ctr is DropDownList)
> {
> // do something
> }
> }
>
> However, i cannot find the repeater control. Any ideas how to do this?
>
> Thanks,


Nov 19 '05 #5

P: n/a
Hi Charliewest,

loop through the repeater.items collection
HTH jd

For Each item As RepeaterItem In rep.Items

If item.ItemIndex > -1 Then

Dim myVal As String

' this assumes you do not know the id of the control
' if you do use then item.FindControl(controlId)
' also if the repeateritem contains more than one checkbox
' or more than one dropdown list you will be left with the
value of the
' last control examined.... but you should get the idea...

For Each con As Control In item.Controls

If TypeOf con Is DropDownList Then

myVal = CType(con, DropDownList).SelectedValue

ElseIf TypeOf con Is CheckBox Then

If CType(con, CheckBox).Checked Then

myVal = CType(con, CheckBox).Text

End If

Else

'do nothing

End If
Next
End If

Next
"charliewest" wrote:
First, thanks Eliyahu for your help.

I don't have nested repeaters, i am only using one. I do have other nested
controls, specifically the DropDownList and CheckBox. The Submit Button is
not part of the Repeater control.

I am assuming that you suggest taht i use the Repeater.Controls collection
to loop?

"Eliyahu Goldin" wrote:
Your original question refers to just one repeater. Do you mean you have
nested repeaters? You can always get to any single one of them and then loop
through its items.

Eliyahu

"charliewest" <ch*********@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
Thanks, but in my scenario, this is not possible. My custom-grid created

with
the repeater controls, comprises, several different DataSets as well as
unique info from constants, session vars, etc... Hence, i need to be able

to
loop through the controls collection. Any ideas?

Thanks again,

"Eliyahu Goldin" wrote:

> You can loop through the repeater Items collection, find the ddls and
> checkboxes with the item's FindControl method, get the values, set them

in
> the dataset table and at the end call the Update method of the data

adapter
> that links the dataset to the database.
>
> Eliyahu
>
> "charliewest" <ch*********@discussions.microsoft.com> wrote in message
> news:B6**********************************@microsof t.com...
> > Hello -
> >
> > I'm using a Repeater control to render information in a very

customized
> > grid-like table. The Repeater control is binded to a DataSet with

several
> > records of information. Within the Repeater control, I've placed
> > DropDownLists and CheckBoxes.
> >
> > When the user has updated the information, he/he clicks the submit

button
> > which is outside the scope of the Repeater control.
> >
> > What i need to do, is read each of the values from DropDownLists and
> > CheckBoxes and save these into the database. How can i read these

controls
> > from code-behind?
> >
> > I was thinking of using:
> >
> > foreach (Control ctr in Page.Controls)
> > {
> > if (ctr is DropDownList)
> > {
> > // do something
> > }
> > }
> >
> > However, i cannot find the repeater control. Any ideas how to do this?
> >
> > Thanks,
>
>
>


Nov 19 '05 #6

P: n/a
This is perfect. Thanks. My code in C# for those who might be interested is:

// Get Data out of Repeater Control
System.Collections.ArrayList ar_Status = new ArrayList();
System.Collections.ArrayList ar_CheckBox = new ArrayList();
foreach (RepeaterItem item in Repeater1.Items)
{
if (item.ItemIndex > -1)
{
foreach (Control ctr in item.Controls)
{
if (ctr is DropDownList)
{
ar_Status.Add(((DropDownList)ctr).SelectedValue);
}
else if (ctr is CheckBox)
{
ar_CheckBox.Add(((CheckBox)ctr).Checked);
}
}
}
}

"london calling" wrote:
Hi Charliewest,

loop through the repeater.items collection
HTH jd

For Each item As RepeaterItem In rep.Items

If item.ItemIndex > -1 Then

Dim myVal As String

' this assumes you do not know the id of the control
' if you do use then item.FindControl(controlId)
' also if the repeateritem contains more than one checkbox
' or more than one dropdown list you will be left with the
value of the
' last control examined.... but you should get the idea...

For Each con As Control In item.Controls

If TypeOf con Is DropDownList Then

myVal = CType(con, DropDownList).SelectedValue

ElseIf TypeOf con Is CheckBox Then

If CType(con, CheckBox).Checked Then

myVal = CType(con, CheckBox).Text

End If

Else

'do nothing

End If
Next
End If

Next
"charliewest" wrote:
First, thanks Eliyahu for your help.

I don't have nested repeaters, i am only using one. I do have other nested
controls, specifically the DropDownList and CheckBox. The Submit Button is
not part of the Repeater control.

I am assuming that you suggest taht i use the Repeater.Controls collection
to loop?

"Eliyahu Goldin" wrote:
Your original question refers to just one repeater. Do you mean you have
nested repeaters? You can always get to any single one of them and then loop
through its items.

Eliyahu

"charliewest" <ch*********@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
> Thanks, but in my scenario, this is not possible. My custom-grid created
with
> the repeater controls, comprises, several different DataSets as well as
> unique info from constants, session vars, etc... Hence, i need to be able
to
> loop through the controls collection. Any ideas?
>
> Thanks again,
>
> "Eliyahu Goldin" wrote:
>
> > You can loop through the repeater Items collection, find the ddls and
> > checkboxes with the item's FindControl method, get the values, set them
in
> > the dataset table and at the end call the Update method of the data
adapter
> > that links the dataset to the database.
> >
> > Eliyahu
> >
> > "charliewest" <ch*********@discussions.microsoft.com> wrote in message
> > news:B6**********************************@microsof t.com...
> > > Hello -
> > >
> > > I'm using a Repeater control to render information in a very
customized
> > > grid-like table. The Repeater control is binded to a DataSet with
several
> > > records of information. Within the Repeater control, I've placed
> > > DropDownLists and CheckBoxes.
> > >
> > > When the user has updated the information, he/he clicks the submit
button
> > > which is outside the scope of the Repeater control.
> > >
> > > What i need to do, is read each of the values from DropDownLists and
> > > CheckBoxes and save these into the database. How can i read these
controls
> > > from code-behind?
> > >
> > > I was thinking of using:
> > >
> > > foreach (Control ctr in Page.Controls)
> > > {
> > > if (ctr is DropDownList)
> > > {
> > > // do something
> > > }
> > > }
> > >
> > > However, i cannot find the repeater control. Any ideas how to do this?
> > >
> > > Thanks,
> >
> >
> >

Nov 19 '05 #7

P: n/a
Did that soultion work for you? I am stuck on the DropDownList being cleared
out on PostBack because the ItemCreated event isnt being called after the
original databind. but if I do the databind then I lose all of the users
changes.

Any ideas?
"charliewest" wrote:
This is perfect. Thanks. My code in C# for those who might be interested is:

// Get Data out of Repeater Control
System.Collections.ArrayList ar_Status = new ArrayList();
System.Collections.ArrayList ar_CheckBox = new ArrayList();
foreach (RepeaterItem item in Repeater1.Items)
{
if (item.ItemIndex > -1)
{
foreach (Control ctr in item.Controls)
{
if (ctr is DropDownList)
{
ar_Status.Add(((DropDownList)ctr).SelectedValue);
}
else if (ctr is CheckBox)
{
ar_CheckBox.Add(((CheckBox)ctr).Checked);
}
}
}
}

"london calling" wrote:
Hi Charliewest,

loop through the repeater.items collection
HTH jd

For Each item As RepeaterItem In rep.Items

If item.ItemIndex > -1 Then

Dim myVal As String

' this assumes you do not know the id of the control
' if you do use then item.FindControl(controlId)
' also if the repeateritem contains more than one checkbox
' or more than one dropdown list you will be left with the
value of the
' last control examined.... but you should get the idea...

For Each con As Control In item.Controls

If TypeOf con Is DropDownList Then

myVal = CType(con, DropDownList).SelectedValue

ElseIf TypeOf con Is CheckBox Then

If CType(con, CheckBox).Checked Then

myVal = CType(con, CheckBox).Text

End If

Else

'do nothing

End If
Next
End If

Next
"charliewest" wrote:
First, thanks Eliyahu for your help.

I don't have nested repeaters, i am only using one. I do have other nested
controls, specifically the DropDownList and CheckBox. The Submit Button is
not part of the Repeater control.

I am assuming that you suggest taht i use the Repeater.Controls collection
to loop?

"Eliyahu Goldin" wrote:

> Your original question refers to just one repeater. Do you mean you have
> nested repeaters? You can always get to any single one of them and then loop
> through its items.
>
> Eliyahu
>
> "charliewest" <ch*********@discussions.microsoft.com> wrote in message
> news:76**********************************@microsof t.com...
> > Thanks, but in my scenario, this is not possible. My custom-grid created
> with
> > the repeater controls, comprises, several different DataSets as well as
> > unique info from constants, session vars, etc... Hence, i need to be able
> to
> > loop through the controls collection. Any ideas?
> >
> > Thanks again,
> >
> > "Eliyahu Goldin" wrote:
> >
> > > You can loop through the repeater Items collection, find the ddls and
> > > checkboxes with the item's FindControl method, get the values, set them
> in
> > > the dataset table and at the end call the Update method of the data
> adapter
> > > that links the dataset to the database.
> > >
> > > Eliyahu
> > >
> > > "charliewest" <ch*********@discussions.microsoft.com> wrote in message
> > > news:B6**********************************@microsof t.com...
> > > > Hello -
> > > >
> > > > I'm using a Repeater control to render information in a very
> customized
> > > > grid-like table. The Repeater control is binded to a DataSet with
> several
> > > > records of information. Within the Repeater control, I've placed
> > > > DropDownLists and CheckBoxes.
> > > >
> > > > When the user has updated the information, he/he clicks the submit
> button
> > > > which is outside the scope of the Repeater control.
> > > >
> > > > What i need to do, is read each of the values from DropDownLists and
> > > > CheckBoxes and save these into the database. How can i read these
> controls
> > > > from code-behind?
> > > >
> > > > I was thinking of using:
> > > >
> > > > foreach (Control ctr in Page.Controls)
> > > > {
> > > > if (ctr is DropDownList)
> > > > {
> > > > // do something
> > > > }
> > > > }
> > > >
> > > > However, i cannot find the repeater control. Any ideas how to do this?
> > > >
> > > > Thanks,
> > >
> > >
> > >
>
>
>

Jun 8 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.