Solved

asp.net findcontrol

Posted on 2014-03-12
5
280 Views
Last Modified: 2014-03-28
inside Wizard1_FinishButtonClick event,
how can I find a value from chkAdd control? The checkbox may be checked by the user. 1 or many.
How to get the list of selected value?

Thanks


<asp:Wizard DisplaySideBar="false" CssClass="form-group" Width="1200px"  ID="Wizard1" runat="server" onfinishbuttonclick="Wizard1_FinishButtonClick">
<WizardSteps>
<asp:WizardStep ID="WizardStep1"  Title="1" runat="server" />
<asp:WizardStep ID="WizardStep3"  Title="2" runat="server">
<asp:DataList runat="server" ID="amenityList" RepeatColumns="5" RepeatDirection="Horizontal">
                                    <ItemTemplate>
                                         <asp:Label Width="160px" runat="server" ID="lblItemDescription" Text='<%# Eval("Description") %>'></asp:Label>
                                        <asp:CheckBox runat="server" ID="chkAdd"  Checked="true" />
                                    </ItemTemplate>
                                  </asp:DataList>                                  
 </asp:WizardStep>
</WizardSteps>
0
Comment
Question by:CoolDev2014
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:Kishan Zunjare
ID: 39925496
You need use itemdatabound event of Datalist;

protected void amenityList_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item ||
              e.Item.ItemType == ListItemType.AlternatingItem)
            {
                CheckBox chk = (CheckBox)e.Item.FindControl("chkAdd");
                if (chk.Checked)
                {
                    Response.Write("chked");
                }
                else
                {
                    Response.Write("not chked");
                }
            }            
        }

Open in new window


To get list of selected checkboxes, you can use some list and add checked values into that list.
0
 

Author Comment

by:CoolDev2014
ID: 39925549
I don't think your codes are working
0
 
LVL 7

Expert Comment

by:Kishan Zunjare
ID: 39925560
Please post your HTML and code behind code for DataList binding
0
 

Author Comment

by:CoolDev2014
ID: 39928454
u can just use the codes i posted. How your amenityList_ItemDataBound will possibly be working?
0
 
LVL 7

Accepted Solution

by:
Kishan Zunjare earned 500 total points
ID: 39928492
Hi CoolDev2014,

Assuming that you are binding amenityList to some datasource, and you need checked items from this datalist on any button click. To get checked items you can use bellow code. Sorry for confusion.

foreach (DataListItem item in amenityList.Items)
            {
                CheckBox chk = (CheckBox)item.FindControl("chkAdd");
                if (chk.Checked)
                {
                    Response.Write("chked <br />");
                }
                else
                {
                    Response.Write("notchked <br />");
                }
            }

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

864 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

16 Experts available now in Live!

Get 1:1 Help Now