Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

DataList Hidden Value

Posted on 2015-02-16
2
76 Views
Last Modified: 2015-02-17
I am trying to get the hiddenfield value in a datalist. However, this is the result:

System.Web.UI.WebControls.HiddenField

        <asp:DataList ID="dataList" RepeatDirection="Horizontal" runat="server">
            <ItemTemplate>
                <asp:CheckBox ID="dataChkbox" AutoPostBack="true" OnCheckedChanged="dataChkbox_CheckedChanged" runat="server" />
                <asp:HiddenField ID="dataPath" Value='<%#Eval("dataValue")%>' runat="server" />
            </ItemTemplate>
        </asp:DataList>

        protected void dataChkbox_CheckedChanged(object sender, EventArgs e)
        {
            var chk = (CheckBox)sender;
            if (chk.Checked)
            {
                var item = (DataListItem)chk.NamingContainer;
                var dataPathVal = (HiddenField)item.FindControl("dataPath");
		label1.text = dataPathVal.ToString(); 
	    }
        }

Open in new window

0
Comment
Question by:RecipeDan
2 Comments
 
LVL 14

Accepted Solution

by:
Lokesh B R earned 500 total points
ID: 40613607
Hi,

You have to use the dataPathVal.Value as below.

protected void dataChkbox_CheckedChanged(object sender, EventArgs e)
        {
            var chk = (CheckBox)sender;
            if (chk.Checked)
            {
                var item = (DataListItem)chk.NamingContainer;
                var dataPathVal = (HiddenField)item.FindControl("dataPath");
               label1.text = dataPathVal.Value;
            }
        }

Open in new window


https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hiddenfield.value(v=vs.110).aspx
0
 
LVL 1

Author Closing Comment

by:RecipeDan
ID: 40613746
Thank you
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# Gridview 1 45
VB.NET 2008 - SQL Timeout 9 34
Iteration Help (Asp.net VB) 5 24
Where is this file? 3 25
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question