suppose I have 5 check boxes. Based on number of check box checked I have to add image and hyper-link to images. (i.e if I have checked 2 check box I have to load only 2 image and link to those 2 loaded images, in-case of 3 check box checked, 3 images needs to be loaded and link to those 3 loaded images).
Is there any possible way that I can do that in asp.net using c#?
If you want to display images or hide right after you select or deselect a check box you need to set the AutoPostBack attribute of the checkboxes controls (or checkboxlist control) to true.
And in the respective OnSelectedIndexChanged event (or the Button1_Click event if that's the case) you simply change the images Visible property to true or false depeding on the options selected.
Also, if you want the user experience to be smoother you may embedd your images markup inside an UpdatePanel and call:
UpdatePanel1.Update();
Got it?
It depends on whether the CheckBoxes are in a CheckBoxList, but assuming they're not put the CheckBoxes in some type of parent container, i.e. a PlaceHolder or a Panel, and you can retrieve the CheckBoxes like this:
foreach (CheckBox chk in PlaceHolder1.Controls.OfType<CheckBox>())
{
if (chk.Checked)
{
//create/load image and hyperlink
}
}
Related
In ListView there are 3 option of SelectionMode
1.Single - only one item can be selected.
2.Multiple - you can select muliple items, one after the other.
3.Extended - You can select multiple items and used Ctrl or Shift key.
I'm need to select some items in ListView as text in TextBox.
i.e. press with the left button of mouse, until the mouse is up.
and mark all between items as Selected.
How can I make it?
Thanks
1.Single: SelectionMode="Single"?
2 Mutiple : i think use binding
enter link description here
3
enter link description here
Or You try this line SelectionMode="Muti..."
Firstly, the porpose of this problem is to display listView of TextBlocks for allow use ItemsSource of ListView for display text for several reasone.
behind each textBlock that contains a word, there are in the ViewModel class named Word. that contains the text of the word and property of IsSelected.
I solve this problem, by adding 3 EventSetter event to the ListViewItem,
1.PreviewMouseLeftDown
2.MouseEnter
3.PreviewMouseLeftUp
and adding a flag of IsInSelection, and two object Word that present the control in the view,1.firstSelectionWord, 2.lastSelectionWord.
and, when the first event raise, i update the current control to be Selected.
and set a flag IsInSelection to true. and set firstSelectionWord = lastSelectionWord = current word pressed.
in the MouseEnter event i checked if IsInSelection is true, and them mark also the current control to Selected=true. set the lastSelectionWord = current word pressed.
and call a method that mark all the Word between them as selected.
in the PreviewMouseLeftUp function, i set the IsInSelection = false.
I only want 1 row to display in a DataGridView, so I want to somehow hide the checkbox that appears in the column header.
This checkbox is intended to select all the checkboxes, which I don't want to allow users to do.
I'm trying to avoid hiding the column headers and disguising some labels as if they were headers.
Note: I already have the code to uncheck all the other checkboxes when a user clicks on a different one.
Update: I left out that I populated the data from a data source. The "Include" column was not attached to the data source, but added from the data source wizard.
After some advanced experimentation (i.e. fooling around), I learned that naming a field/column "Selected" in the data source will not only cause it to be automatically included in the data grid view as a checkbox, but the header will not have a checkbox and behaves as desired.
Finagling my way to success ...
I am kind of new to C# and Asp.Net, so this question might sound repetitive but I am not able to find a solution for this particular problem.
I have two buttons on my HTML page and a single class in .cs file. On one of the button clicks, I create a table programmatically (dynamically).
The table contains some checkboxes which are also created dynamically.
Table creation is one of the last tasks that I perform. Before that, I read several files and extract data from them to create the table. After the table is drawn, the user can select one or more checkboxes.
Now, how on second button click, can I know that which of the checkboxes were checked before the page reload? Currently I have made all these checkboxes member variables of the the only class that I have in the .cs file.
I tried adding checkbox event handler through C# code. But the handler is not getting called when the checkbox is checked. I don't want to set the 'autopostback' property of the checkbox to true since if thats set true, the page reloads after checking one of the checkboxes. User should be able to select multiple checkboxes.
Add your checkboxes dynamically and set a unique name for each checkbox. Checkboxes are only posted back to the server if the checkbox is checked, so you can test to see if it is checked by checking Request.Form to see if the name exists. For example, lets say you named your check boxes chk_[0-9] (i.e. chk_0, chk_1 etc till 9), you could check if they ticked by doing:
for(int i=0; i < 10; i++)
{
string chk_name = "chk_" + i.ToString();
if (Request.Form[chk_name] != null)
{
//checkbox is checked
}
else
{
//checkbox is not checked
}
}
I ran into a new problem on my project;
I have a panel on my page in which I add labels, radiobuttons and 2 imagebuttons using pure programming code (because the number of labels and radiobuttons can be different).
I gave each radiobutton a special ID so I know in which content of the panel it belongs.
Now the big problem is I don't know how to get things from the panel.
Let's say the panel was filled with labels and radiobuttons (labels for questions and radiobuttons for the answering score 0-10) and I scored every question as asked, how do I for example select every radiobutton from the panel with an id that ends with '5' and get it's value ?
Name of the panel = pnlMain
my code : http://pastebin.com/gv8ycMY4
Thanks
I Hope you guys could help me out here because I'm really stuck on this.
grtz,
Nico
You could itterate through the panel's controls to get each radiobuttonlist, then itterate through those controls to get the radio buttons.
foreach (Control RBL in pnlMain.Controls)
{
if (RBL is RadioButtonList)
{
foreach (ListItem LI in (RBL as RadioButtonList).Items)
{
if (LI.Text.EndsWith("5") && LI.Selected)
{
// Do something with the radiobutton
}
}
}
}
Found the answer finally;
If you want to keep these dynamic controls after postback etc :
F.E. me, i used a SelectedIndexChange to fill up my panel with dynamic controls.
I made another method named laden() in wich i wrote my code to display these dynamic controls.
If you want these controls to pass postbacks etc simply place the following peace of code into the Page_Load method:
if (Page.IsPostBack) {
laden();
}
Wich means, if you get a postback, it will Re-load these controls after postback.
Even if you got data inserted in a textbox or radiobuttons wich where selected, it will still be the same as before the postback, no data lost.
enjoy.
I have to filter GridView data based on the Tab Panel selected,
Here is the scenario:
I have the following tabs
All | Tab A | Tab B | Tab C
When I click on "All" tab, I get 10 records and my GridView contains 10 records,
But when I click on Tab A, my GridView need to filter and show 5 records
Right now, I am using the separate GridView for each tab and binding to same DataSourceID.
And using OnActiveTabChanged event to filter the data, but this is invoking underlying method to-execute 4 times (because of 4 tab panels), no problem with the user experience but
there is performance issue...
I am trying to see, if I can use the :
Same GrigView in all the Tab Panels for this type of scenario
Any help is much appreciate, thanks!!
If you want to use a single GridView on all tabs, try invoking the underlying method (that populates the GridView) in OnPreRender instead of OnActiveTabChanged. Make it conditional on which tab is active, and filter accordingly.
You can use the RowFilter property on a DataView and have each tab apply the one you need.
ie DataView1.RowFilter = "Column='ColumnValue'" then set the datasource/databind.