473,545 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting value of server control

hi !
i have following code to display some text on a web form,after
getting it from database.

<asp:DataList ID="DataList1" runat="server"
DataSourceID="S qlDataSource1">
<ItemTemplate >
<asp:LinkButt on ID="links" runat="server" Text='<%#
Eval("links") %>' OnClick="LinkBu tton1_Click"></asp:LinkButton> <br />

<asp:Label ID="textLabel" runat="server" Text='<%#
Eval("text") %>' ForeColor="Dark SlateBlue"></asp:Label><br />

<asp:Label ID="urlsLabel" runat="server" Text='<%#
Eval("urls") %>' ForeColor="Dark SeaGreen"></asp:Label><br />

<asp:HiddenFiel d ID="page" runat="server" Value='<%#
Eval("page_ref" ) %>'></asp:HiddenField ><br />
<br />
</ItemTemplate>
</asp:DataList>

and i want to access the value of hiddenfield in my aspx.cs file for
some manipulation.fo r this purpose i'm using the following code:
for(i=0;i<DataL ist1.items.coun t;i++)
{
HiddenField hd = (HiddenField)Da taList1.Items[2].FindControl("p age");
string s = (hd.Value) as string;
}

its giving me the whole record of datalist.but i want to get only the
selected item against my record.
any one have idea about it,plz rply me.

Apr 6 '07 #1
4 4566
Good morning Bushi,

Take a look at your code again. You're looping through the items accessing
third item (Item[2]) ein every iteration. In addition to that, there is no
need for that as datalist has a property to check which item is currently
selected, it should be as following:

int index = DataList1.Selec tedIndex;
string value = String.Empty;

if (index >= 0)
{
HiddenField hidden = (HiddenField)
DataList1.Items[index].FindControl("p age");
value = hidden.Value;
}

--
Milosz
"bushi" wrote:
hi !
i have following code to display some text on a web form,after
getting it from database.

<asp:DataList ID="DataList1" runat="server"
DataSourceID="S qlDataSource1">
<ItemTemplate >
<asp:LinkButt on ID="links" runat="server" Text='<%#
Eval("links") %>' OnClick="LinkBu tton1_Click"></asp:LinkButton> <br />

<asp:Label ID="textLabel" runat="server" Text='<%#
Eval("text") %>' ForeColor="Dark SlateBlue"></asp:Label><br />

<asp:Label ID="urlsLabel" runat="server" Text='<%#
Eval("urls") %>' ForeColor="Dark SeaGreen"></asp:Label><br />

<asp:HiddenFiel d ID="page" runat="server" Value='<%#
Eval("page_ref" ) %>'></asp:HiddenField ><br />
<br />
</ItemTemplate>
</asp:DataList>

and i want to access the value of hiddenfield in my aspx.cs file for
some manipulation.fo r this purpose i'm using the following code:
for(i=0;i<DataL ist1.items.coun t;i++)
{
HiddenField hd = (HiddenField)Da taList1.Items[2].FindControl("p age");
string s = (hd.Value) as string;
}

its giving me the whole record of datalist.but i want to get only the
selected item against my record.
any one have idea about it,plz rply me.

Apr 6 '07 #2
On Apr 6, 4:46 pm, Milosz Skalecki [MCAD] <mily...@DONTLI KESPAMwp.pl>
wrote:
thanks 4 rplying, there is still a problem,i want to get one selected
value at a time,but the code u sent returns the null index,i'm not
getting how to retrieve the slected value,lets i try to explain what i
want,
the following is my datalist result:

Get More Visitors (its a hyper link)
Need a Boost in Site Visitors? Choose How Many Yo
www.lexiesreviews.com/page2.html
Pay-per-click
Ni hittade hit! Vill ni också bli hittade? Kontak
www.resultatmedia.se
The own search engine
with ranking function & real bot AdSense power po
www.myengines.us
Wealthy Affiliate Scam
Raw Review of Wealthy Affiliate! The Big Nasty- E
www.review-one.net/1/?key=Y2

and i want to get the value like "Pay-per-click" once i click on
it,and using its index i want to get the whole record.but when i click
on it returns null refrence,so guide me what i should do?
Good morning Bushi,

Take a look at your code again. You're looping through the items accessing
third item (Item[2]) ein every iteration. In addition to that, there is no
need for that as datalist has a property to check which item is currently
selected, it should be as following:

int index = DataList1.Selec tedIndex;
string value = String.Empty;

if (index >= 0)
{
HiddenField hidden = (HiddenField)
DataList1.Items[index].FindControl("p age");
value = hidden.Value;

}

--
Milosz

"bushi" wrote:
hi !
i have following code to display some text on a web form,after
getting it from database.
<asp:DataList ID="DataList1" runat="server"
DataSourceID="S qlDataSource1">
<ItemTemplate >
<asp:LinkButt on ID="links" runat="server" Text='<%#
Eval("links") %>' OnClick="LinkBu tton1_Click"></asp:LinkButton> <br />
<asp:Label ID="textLabel" runat="server" Text='<%#
Eval("text") %>' ForeColor="Dark SlateBlue"></asp:Label><br />
<asp:Label ID="urlsLabel" runat="server" Text='<%#
Eval("urls") %>' ForeColor="Dark SeaGreen"></asp:Label><br />
<asp:HiddenFiel d ID="page" runat="server" Value='<%#
Eval("page_ref" ) %>'></asp:HiddenField ><br />
<br />
</ItemTemplate>
</asp:DataList>
and i want to access the value of hiddenfield in my aspx.cs file for
some manipulation.fo r this purpose i'm using the following code:
for(i=0;i<DataL ist1.items.coun t;i++)
{
HiddenField hd = (HiddenField)Da taList1.Items[2].FindControl("p age");
string s = (hd.Value) as string;
}
its giving me the whole record of datalist.but i want to get only the
selected item against my record.
any one have idea about it,plz rply me.- Hide quoted text -

- Show quoted text -

Apr 9 '07 #3
Howdy,

There is no need to use hidden fields for this purpose. Use DataKeyFields
property to specify which column should be used as row identificator and get
its value via SelectedValue property and SelectedIndexCh anged event:

<script runat="server">
protected void DataList1_Selec tedIndexChanged (object sender, EventArgs e)
{
// i assumed page_ref type is string
DataList dataList = (DataList)sende r;
string pagerRef = (string) dataList.Select edValue;
// use the selected page ref value here...
}
</script>

<asp:DataList ID="DataList1" runat="server" DataKeyField="p age_ref"
OnSelectedIndex Changed="DataLi st1_SelectedInd exChanged">
<ItemTemplate >
<asp:LinkButt on CommandName="Se lect" ID="links" runat="server" Text='<%#
Eval("links") %>' /><br />
<asp:Label ID="textLabel" runat="server" Text='<%# Eval("text") %>'
ForeColor="Dark SlateBlue" /><br />
<asp:Label ID="urlsLabel" runat="server" Text='<%# Eval("urls") %>'
ForeColor="Dark SeaGreen" /><br />
<br />
</ItemTemplate>
<SelectedItemSt yle BackColor="red" />
</asp:DataList>

Hope this helps
--
Milosz
"bushi" wrote:
On Apr 6, 4:46 pm, Milosz Skalecki [MCAD] <mily...@DONTLI KESPAMwp.pl>
wrote:
thanks 4 rplying, there is still a problem,i want to get one selected
value at a time,but the code u sent returns the null index,i'm not
getting how to retrieve the slected value,lets i try to explain what i
want,
the following is my datalist result:

Get More Visitors (its a hyper link)
Need a Boost in Site Visitors? Choose How Many Yo
www.lexiesreviews.com/page2.html
Pay-per-click
Ni hittade hit! Vill ni också bli hittade? Kontak
www.resultatmedia.se
The own search engine
with ranking function & real bot AdSense power po
www.myengines.us
Wealthy Affiliate Scam
Raw Review of Wealthy Affiliate! The Big Nasty- E
www.review-one.net/1/?key=Y2

and i want to get the value like "Pay-per-click" once i click on
it,and using its index i want to get the whole record.but when i click
on it returns null refrence,so guide me what i should do?
Good morning Bushi,

Take a look at your code again. You're looping through the items accessing
third item (Item[2]) ein every iteration. In addition to that, there is no
need for that as datalist has a property to check which item is currently
selected, it should be as following:

int index = DataList1.Selec tedIndex;
string value = String.Empty;

if (index >= 0)
{
HiddenField hidden = (HiddenField)
DataList1.Items[index].FindControl("p age");
value = hidden.Value;

}

--
Milosz

"bushi" wrote:
hi !
i have following code to display some text on a web form,after
getting it from database.
<asp:DataList ID="DataList1" runat="server"
DataSourceID="S qlDataSource1">
<ItemTemplate >
<asp:LinkButt on ID="links" runat="server" Text='<%#
Eval("links") %>' OnClick="LinkBu tton1_Click"></asp:LinkButton> <br />
<asp:Label ID="textLabel" runat="server" Text='<%#
Eval("text") %>' ForeColor="Dark SlateBlue"></asp:Label><br />
<asp:Label ID="urlsLabel" runat="server" Text='<%#
Eval("urls") %>' ForeColor="Dark SeaGreen"></asp:Label><br />
<asp:HiddenFiel d ID="page" runat="server" Value='<%#
Eval("page_ref" ) %>'></asp:HiddenField ><br />
<br />
</ItemTemplate>
</asp:DataList>
and i want to access the value of hiddenfield in my aspx.cs file for
some manipulation.fo r this purpose i'm using the following code:
for(i=0;i<DataL ist1.items.coun t;i++)
{
HiddenField hd = (HiddenField)Da taList1.Items[2].FindControl("p age");
string s = (hd.Value) as string;
}
its giving me the whole record of datalist.but i want to get only the
selected item against my record.
any one have idea about it,plz rply me.- Hide quoted text -
- Show quoted text -


Apr 9 '07 #4
On Apr 10, 2:26 am, Milosz Skalecki [MCAD] <mily...@DONTLI KESPAMwp.pl>
wrote:
Howdy,

There is no need to use hidden fields for this purpose. Use DataKeyFields
property to specify which column should be used as row identificator and get
its value via SelectedValue property and SelectedIndexCh anged event:

<script runat="server">
protected void DataList1_Selec tedIndexChanged (object sender, EventArgs e)
{
// i assumed page_ref type is string
DataList dataList = (DataList)sende r;
string pagerRef = (string) dataList.Select edValue;
// use the selected page ref value here...
}
</script>

<asp:DataList ID="DataList1" runat="server" DataKeyField="p age_ref"
OnSelectedIndex Changed="DataLi st1_SelectedInd exChanged">
<ItemTemplate >
<asp:LinkButt on CommandName="Se lect" ID="links" runat="server" Text='<%#
Eval("links") %>' /><br />
<asp:Label ID="textLabel" runat="server" Text='<%# Eval("text") %>'
ForeColor="Dark SlateBlue" /><br />
<asp:Label ID="urlsLabel" runat="server" Text='<%# Eval("urls") %>'
ForeColor="Dark SeaGreen" /><br />
<br />
</ItemTemplate>
<SelectedItemSt yle BackColor="red" />
</asp:DataList>

Hope this helps
--
Milosz

"bushi" wrote:
On Apr 6, 4:46 pm, Milosz Skalecki [MCAD] <mily...@DONTLI KESPAMwp.pl>
wrote:
thanks 4 rplying, there is still a problem,i want to get one selected
value at a time,but the code u sent returns the null index,i'm not
getting how to retrieve the slected value,lets i try to explain what i
want,
the following is my datalist result:
Get More Visitors (its a hyper link)
Need a Boost in Site Visitors? Choose How Many Yo
www.lexiesreviews.com/page2.html
Pay-per-click
Ni hittade hit! Vill ni också bli hittade? Kontak
www.resultatmedia.se
The own search engine
with ranking function & real bot AdSense power po
www.myengines.us
Wealthy Affiliate Scam
Raw Review of Wealthy Affiliate! The Big Nasty- E
www.review-one.net/1/?key=Y2
and i want to get the value like "Pay-per-click" once i click on
it,and using its index i want to get the whole record.but when i click
on it returns null refrence,so guide me what i should do?
Good morning Bushi,
Take a look at your code again. You're looping through the items accessing
third item (Item[2]) ein every iteration. In addition to that, there is no
need for that as datalist has a property to check which item is currently
selected, it should be as following:
int index = DataList1.Selec tedIndex;
string value = String.Empty;
if (index >= 0)
{
HiddenField hidden = (HiddenField)
DataList1.Items[index].FindControl("p age");
value = hidden.Value;
}
--
Milosz
"bushi" wrote:
hi !
i have following code to display some text on a web form,after
getting it from database.
<asp:DataList ID="DataList1" runat="server"
DataSourceID="S qlDataSource1">
<ItemTemplate >
<asp:LinkButt on ID="links" runat="server" Text='<%#
Eval("links") %>' OnClick="LinkBu tton1_Click"></asp:LinkButton> <br />
<asp:Label ID="textLabel" runat="server" Text='<%#
Eval("text") %>' ForeColor="Dark SlateBlue"></asp:Label><br />
<asp:Label ID="urlsLabel" runat="server" Text='<%#
Eval("urls") %>' ForeColor="Dark SeaGreen"></asp:Label><br />
<asp:HiddenFiel d ID="page" runat="server" Value='<%#
Eval("page_ref" ) %>'></asp:HiddenField ><br />
<br />
</ItemTemplate>
</asp:DataList>
and i want to access the value of hiddenfield in my aspx.cs file for
some manipulation.fo r this purpose i'm using the following code:
for(i=0;i<DataL ist1.items.coun t;i++)
{
HiddenField hd = (HiddenField)Da taList1.Items[2].FindControl("p age");
string s = (hd.Value) as string;
}
its giving me the whole record of datalist.but i want to get only the
selected item against my record.
any one have idea about it,plz rply me.- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
thanx milosz!!!!!!!
i have followed ur instructions,th ey help me in solving
my problem.

Apr 10 '07 #5

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

Similar topics

6
2179
by: tshad | last post by:
I need to get to a status label I have on my footer section of my datalist. There is no event happening that would go to the footer. I am just doing some processing and want to update the label on the footer. At the moment, I go through the dataListItems like so: for each oItem as DataListItem in DataList1.Items trace.warn("inside for...
4
1208
by: regaliel | last post by:
I am using a datalist control (dlist_myfavorites) and this control is bound to a sqldatareader source. Datalist is basicly populated by the following sp. CREATE PROCEDURE ( @mguid as nvarchar(50) -- member guid id ) AS
1
2682
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting, paginantion or accepting the add and remove item events. What i am observing is that none of the vents are happening... (Sort, page, or item). I am sure I...
4
2496
by: Patrick.O.Ige | last post by:
I'm DataBinding a CheckBoxList and i want to get the checkboxes selected when the page is loaded depending on a Boolean value from the Database.. chkDebtor.DataSource = objDR chkDebtor.DataValueField = "checked" -- this is a column in the table that returns 1 or 0 chkDebtor.DataTextField = "DebtorCode" chkDebtor.DataBind() Dim i As...
5
5937
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an event is fired by one of the controls contained in the User Control, these variable are reset. Here is my current code (I have a little more to add...
3
1440
by: PJ6 | last post by:
When I have client-side script like this - document.forms.submit('test') how do I access, from server-side code, the value I put in the submit method? Also, is it possible to get the control's containing form name so I can emite script like this -
1
1663
by: Roffers | last post by:
Okay I have a parent page, we'll call it parent.aspx and it holds the following two user controls <uc1:Box1 id="Box1" runat="server"></uc1:Box1<----THIS CONTAINS A DROP DOWN LIST <br> <uc1:Box2 id="Box2" runat="server"></uc1:Box2<----THIS CONTAINS A DATALIST In Box1, I have a dropdown list that gets selected and should set
3
6845
by: Jeff | last post by:
Hey ASP.NET 2.0 Below you see the code I'm having problem with. In the Open_Message event/method I want to get the value of the HiddenField at the row in the repeater control I clicked.... my goal is to get the id (not a control Id, but an id related to a database record) of a row in the repeater control. I don't want to use Get... I've...
1
1858
by: Alec MacLean | last post by:
Hi, Outline of problem: I've built a set of user controls that are used to output questions for a survey and gather the responses using simple radio buttons. I'm adding an optional textbox to the question control to allow individual typed responses per question. I've got a maximum length to enforce which matches the underlying data...
1
2818
by: bushi | last post by:
hi! i'm getting the data form the database by using datalist control,and have assigned the value to hidden field control in aspx file,now i want to get the value of hidden field in my aspx.cs file,for some manipulations.how i can get it? code is given below: <asp:DataList ID="DataList1" runat="server" DataKeyField="urls"...
0
7479
marktang
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...
0
7411
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7669
Oralloy
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. ...
0
5987
agi2029
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...
1
5343
isladogs
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...
0
3468
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...
0
3450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
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
1
1028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.