Solved

asp.net findcontrol

Posted on 2014-03-12
5
282 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

790 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