Solved

asp.net findcontrol

Posted on 2014-03-12
5
278 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
Comment Utility
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
Comment Utility
I don't think your codes are working
0
 
LVL 7

Expert Comment

by:Kishan Zunjare
Comment Utility
Please post your HTML and code behind code for DataList binding
0
 

Author Comment

by:CoolDev2014
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Limiting string to two deciamls 18 30
Remove Protocol if at start of string? 3 11
Problem to page 4 11
XML & .net 5 0
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…

762 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

6 Experts available now in Live!

Get 1:1 Help Now