Solved

asp.net findcontrol

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

770 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