473,394 Members | 1,709 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,394 software developers and data experts.

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="SqlDataSource1">
<ItemTemplate>
<asp:LinkButton ID="links" runat="server" Text='<%#
Eval("links") %>' OnClick="LinkButton1_Click"></asp:LinkButton><br />

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

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

<asp:HiddenField 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.for this purpose i'm using the following code:
for(i=0;i<DataList1.items.count;i++)
{
HiddenField hd = (HiddenField)DataList1.Items[2].FindControl("page");
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 4559
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.SelectedIndex;
string value = String.Empty;

if (index >= 0)
{
HiddenField hidden = (HiddenField)
DataList1.Items[index].FindControl("page");
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="SqlDataSource1">
<ItemTemplate>
<asp:LinkButton ID="links" runat="server" Text='<%#
Eval("links") %>' OnClick="LinkButton1_Click"></asp:LinkButton><br />

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

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

<asp:HiddenField 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.for this purpose i'm using the following code:
for(i=0;i<DataList1.items.count;i++)
{
HiddenField hd = (HiddenField)DataList1.Items[2].FindControl("page");
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...@DONTLIKESPAMwp.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.SelectedIndex;
string value = String.Empty;

if (index >= 0)
{
HiddenField hidden = (HiddenField)
DataList1.Items[index].FindControl("page");
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="SqlDataSource1">
<ItemTemplate>
<asp:LinkButton ID="links" runat="server" Text='<%#
Eval("links") %>' OnClick="LinkButton1_Click"></asp:LinkButton><br />
<asp:Label ID="textLabel" runat="server" Text='<%#
Eval("text") %>' ForeColor="DarkSlateBlue"></asp:Label><br />
<asp:Label ID="urlsLabel" runat="server" Text='<%#
Eval("urls") %>' ForeColor="DarkSeaGreen"></asp:Label><br />
<asp:HiddenField 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.for this purpose i'm using the following code:
for(i=0;i<DataList1.items.count;i++)
{
HiddenField hd = (HiddenField)DataList1.Items[2].FindControl("page");
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 SelectedIndexChanged event:

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

<asp:DataList ID="DataList1" runat="server" DataKeyField="page_ref"
OnSelectedIndexChanged="DataList1_SelectedIndexCha nged">
<ItemTemplate>
<asp:LinkButton CommandName="Select" ID="links" runat="server" Text='<%#
Eval("links") %>' /><br />
<asp:Label ID="textLabel" runat="server" Text='<%# Eval("text") %>'
ForeColor="DarkSlateBlue" /><br />
<asp:Label ID="urlsLabel" runat="server" Text='<%# Eval("urls") %>'
ForeColor="DarkSeaGreen" /><br />
<br />
</ItemTemplate>
<SelectedItemStyle BackColor="red" />
</asp:DataList>

Hope this helps
--
Milosz
"bushi" wrote:
On Apr 6, 4:46 pm, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.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.SelectedIndex;
string value = String.Empty;

if (index >= 0)
{
HiddenField hidden = (HiddenField)
DataList1.Items[index].FindControl("page");
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="SqlDataSource1">
<ItemTemplate>
<asp:LinkButton ID="links" runat="server" Text='<%#
Eval("links") %>' OnClick="LinkButton1_Click"></asp:LinkButton><br />
<asp:Label ID="textLabel" runat="server" Text='<%#
Eval("text") %>' ForeColor="DarkSlateBlue"></asp:Label><br />
<asp:Label ID="urlsLabel" runat="server" Text='<%#
Eval("urls") %>' ForeColor="DarkSeaGreen"></asp:Label><br />
<asp:HiddenField 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.for this purpose i'm using the following code:
for(i=0;i<DataList1.items.count;i++)
{
HiddenField hd = (HiddenField)DataList1.Items[2].FindControl("page");
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...@DONTLIKESPAMwp.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 SelectedIndexChanged event:

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

<asp:DataList ID="DataList1" runat="server" DataKeyField="page_ref"
OnSelectedIndexChanged="DataList1_SelectedIndexCha nged">
<ItemTemplate>
<asp:LinkButton CommandName="Select" ID="links" runat="server" Text='<%#
Eval("links") %>' /><br />
<asp:Label ID="textLabel" runat="server" Text='<%# Eval("text") %>'
ForeColor="DarkSlateBlue" /><br />
<asp:Label ID="urlsLabel" runat="server" Text='<%# Eval("urls") %>'
ForeColor="DarkSeaGreen" /><br />
<br />
</ItemTemplate>
<SelectedItemStyle BackColor="red" />
</asp:DataList>

Hope this helps
--
Milosz

"bushi" wrote:
On Apr 6, 4:46 pm, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.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.SelectedIndex;
string value = String.Empty;
if (index >= 0)
{
HiddenField hidden = (HiddenField)
DataList1.Items[index].FindControl("page");
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="SqlDataSource1">
<ItemTemplate>
<asp:LinkButton ID="links" runat="server" Text='<%#
Eval("links") %>' OnClick="LinkButton1_Click"></asp:LinkButton><br />
<asp:Label ID="textLabel" runat="server" Text='<%#
Eval("text") %>' ForeColor="DarkSlateBlue"></asp:Label><br />
<asp:Label ID="urlsLabel" runat="server" Text='<%#
Eval("urls") %>' ForeColor="DarkSeaGreen"></asp:Label><br />
<asp:HiddenField 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.for this purpose i'm using the following code:
for(i=0;i<DataList1.items.count;i++)
{
HiddenField hd = (HiddenField)DataList1.Items[2].FindControl("page");
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,they 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
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...
4
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...
1
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,...
4
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...
5
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...
3
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...
1
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>...
3
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...
1
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...
1
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...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.