Radcombo box not preserved the selected item value - asp.net

<telerik:RadComboBox ID="radcmb" runat="server" MarkFirstMatch="true">
</telerik:RadComboBox>
radcmb.Items.Clear();
radcmb.Text = String.Empty;
radcmb.DataSource = DS;
radcmb.DataTextField ="DESCRIPTION";
radcmb.DataValueField ="ID";
radcmb.DataBind();
and i am setting the datasource of the combo box on page_load event, the problem is whenever i have select any item from the combo box and click outside / any other section of the page, its de-select the item and select the first item from the list.
i tried below solution - but it didn't helped me.
RadComboBox changing selected item when clicking on other parts of page

Related

How to get the items selected in a dropdowncheckbox in asp.net?

I have a code that gives me the item selected in a dropdownlist but I can´t make it work for a dropdowncheckbox. In the following:
var Activity= document.getElementById("Cbo_ActivityTypes").value
var Brand = document.getElementById("Cbo_Brand").value
Alert (Activity)
Alert (Brand)
Alert (activity) shows a window with the ID of the item selected, but the Alert(Brand) shows a windows saying undefined. It doesn't recognize that there were items selected in the field Brand.
Codes that load each box:
asp:DropDownList ID="Cbo_ActivityType" runat="server" Width="143px" AutoPostBack="True">
asp:DropDownCheckBoxes ID="Cbo_Brand" runat="server" Width="180px" UseSelectAllNode="False">
Anyone can give some help on this issue?
It is an asp webControl. So to get your Id in html use '<%=ID.ClientID%>'
var Activity= document.getElementById("<%=Cbo_ActivityTypes.ClientID%>").value
var Brand = document.getElementById("<%=Cbo_Brand.ClientID%>").value

Empty Message showing in RadComboBox

I have a RadComboBox with an empty message on my page inside a radgrid. The combobox is populated in the ItemDataBound event for the containing grid. The empty message shows in each radcombobox on the page.
My problem is that the position may have been selected previously & although I could get the value to display, since putting in the empty message, it does not show this value. The empty message is shown, even though this particular combobox is not empty.
The previously selected item does appear in the drop down but the radcombobox seems to be thinking it is still empty. Have I missed something?
asp:
<telerik:RadComboBox ID="cboPosi" runat="server" DataSourceID="LabourDataSource" AllowCustomText="True"
DataTextField="Pos" DataValueField="PosDesc" EnableAutomaticLoadOnDemand="true" ShowMoreResultsBox="true"
EnableVirtualScrolling="true" ItemsPerRequest="10" EmptyMessage="Type here">
</telerik:RadComboBox>
vb.net:
Dim combo As RadComboBox = DirectCast(item.FindControl("cboPosi"), RadComboBox)
Dim selectedItem As New RadComboBoxItem()
selectedItem.Text = selectedTitle
selectedItem.Value = selectedVal
combo.Items.Add(selectedItem)
selectedItem.DataBind()
When using LoadOnDemand you cannot add items to the RadComboBox, you can however set the Text and SelectedValue attributes to mimic selecting an option (See here).
You might also find this Telerik article useful
The problem turned out to be that I was not actually selecting the new item I had made. Without an empty message, this item was being displayed as selected.
Setting the inserted item as the selected item causes it to be displayed correctly instead of the empty message:
Dim combo As RadComboBox = DirectCast(item.FindControl("cboPosi"), RadComboBox)
Dim selectedItem As New RadComboBoxItem()
selectedItem.Text = selectedTitle
selectedItem.Value = selectedVal
combo.Items.Add(selectedItem)
selectedItem.DataBind()
combo.SelectedIndex = 0

Cascading dropdown in ASP.Net is not working fine

Hi - I know this sounds simple, but I am having trouble with some functionality to be achieved. Please refer the attached screen shot of the situation. This is what I am doing:
On page load I am loading the first drop down of Product / Service
BAsed on the selection of the Product dropdown I am populating the second dropdown "Category". I am making the database call to make this happen.
Based on the selection of the Category I am populating the third drop down of the price. I am making database call to get the information for this drop down.
Based on the selection of third (Price) dropdown, I am hiding / showing the panels.
Each dropdown is doing a post back to make the call to the datbase to get the details for the subsequent dropdown.
Everything seems to be working during first run, but the problem comes when I try a combination of the drop down. Following are the problems I am having:
Panel once rendered doesn't go away if I select different option from Dropdown1 and 2.
After subsequent run, the values are added up after each post back. For example if I have a product "Toy Car" in the product / service dropdown, it is now appearing twice and so on.
If the user selects the default option "Select Product", "Select Category" etc. The entire hierarchy should be reset. For example if the previous selection in the Product dropdown was "Toy Car", and now I select the default option "Select Product". It should reset "Category", Price and Panel visibility.
Please let me know how this can be done.
Thanks for the help.
On three DropDownLists
1 You set AutoPostBack="true"
2 You define OnSelectIndexChanged
<asp:dropdownlist id="ddl1" runa="server" Autopostback="true" onselectindexChanged="ddl1_selectindexChanged"/>
<asp:dropdownlist id="ddl2" runa="server" Autopostback="true" onselectindexChanged="ddl2_selectindexChanged"/>
<asp:dropdownlist id="ddl3" runa="server" Autopostback="true" onselectindexChanged="ddl3_selectindexChanged"/>
You must define page_load with this strategy
If(! IsPostBack)
{
//Bind dropdownlist
}
On each selectindexChanged, get value and execute selection in database, and bind your dropdownlist.
void ddl1_selectindexChanged(Object sender, EventArgs e)
{
//Get Selected Values
//For examlpe you can use SelectedValue property
var value1 = ddl1.SelectedValue;
//Request your database
//And bind your dropdownlist of sub categories
...
}
void ddl2_selectindexChanged(Object sender, EventArgs e) 
{
...
}
void ddl3_selectindexChanged(Object sender, EventArgs e)
{
..;
}
Do following things:
1) Second and Third dropdown should be disabled until user select the first drop down then enable second dropdown when user selects second dropdown then enable the third drop down.
2) On post back, Clear the Items in the DropDownList and them bind them with the datasource again. Simply create a function for each dropdown and call it on PostBack after clearing DropDownList by calling Clear method of dropdownlist.
3) To reset the entire hierarchy, Set the SeletecedIndex of all the dropdowns to Zero or -1;

How to get gridview cell value when i click on cell dynamically in ASP.Net

I am developing a movie theater seats booking website,. I have placed images as Seats in asp:gridview(all cells) using ImageButton. For the selected seat, when the user clicks on it, the ImageButton(cell) is set for that seat.
I need to get the seat that was clicked from the gridview. How am I able to do this?
You can find the ImageButton on the RowCommand event of the grid view.
Code part:
string strType="";
ImageButton img = (ImageButton)e.CommandSource;
strType = img.Attributes["TypeID"].ToString();
Designer part:
<asp:ImageButton ID="imgBtn" runat="server" ImageUrl="image"
TypeID="..Give your value.." />

ASP.NET: Gridview Showing a button on a row, when a row cell vlaue = false in the Bound row from the database

I have a GridView binded to a datasource, i was wondering of how i can check a row cell value (bool) from the database row being bound , and then show a button on the rows where the cell value equals to false..
i am using OndataBound Event to retrieve the Gridview-row being bound, i take the ID show, run another procedure against the database to find the value of the cell from the corresponding Database row..
but i cant figure out how to add the button..
also is there any other ways to handle this scenario?
Solution 1: Create a button with an ID where you want it in the gridview, with an attribute visible=false. Whenever you want to show the button, retrieve it (currentGridRow.FindControl("chosen button ID")) and set it's visible attribute to true.
put your button in a templatefield, like that:
<asp:TemplateField HeaderText="foobar" >
<ItemTemplate>
<asp:ImageButton ID="plusbutton" CssClass="cplusButton" ToolTip="plusButton" OnClick="buttonAdd_Click" runat="server" Visible = "false"/>
</ItemTemplate>
</asp:TemplateField>
Solution 2: dynamically create the button (Button b = new Button; currentGridRow.Cell[].Controls.Add(b);), but it's a pain to deal with the viewstate and the events handler. Don't go that way.

Resources