Solved

DataList Hidden Value

Posted on 2015-02-16
2
66 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
Comment Utility
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
Comment Utility
Thank you
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now