Solved

asp.net findcontrol

Posted on 2014-03-12
5
283 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
[X]
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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Rotate images for Web Page 11 26
Video Tutorial help 2 38
ASP.net Will we ever be able to build mobile apps in it 6 28
Put javascript to get dropdown value 3 22
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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

756 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