I have a RadGrid within which one of my columns is a GridTemplateColumn, which has a RadComboBox loading some items (the Edit mode is set to 'PopUp').
What I want is, if while searching for an item in the RadComboBox, no item is found, then give the user an option to add a new item. Currently, just for testing purposes, I want to be able to show a message if no item is found. This is what I have tried till now.
My RadComboBox within the RadGrid is defined as follows:
<EditItemTemplate>
<telerik:RadComboBox runat="server" ID="Product_PKRadComboBox"
ShowDropDownOnTextboxClick="false" ShowMoreResultsBox="true" EnableVirtualScrolling="true"
EnableLoadOnDemand="true" EnableAutomaticLoadOnDemand="true" ItemsPerRequest="10"
OnItemsRequested="Product_PKRadComboBox_ItemsRequested" AllowCustomText="true"
Filter="StartsWith" DataSourceID="SqlProducts" DataTextField="ProductCode"
DataValueField="Product_PK"></telerik:RadComboBox>
</EditItemTemplate>
So I am checking my logic in the 'OnItemsRequested' event as follows:
protected void Product_PKRadComboBox_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
//RadComboBox combo = (RadComboBox)sender;
if (e.EndOfItems && e.NumberOfItems==0)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "testMessage", "alert('Product Not Found. Do you want to add a Custom Product?');", true);
//Page.ClientScript.RegisterStartupScript(typeof(Page), "some_name", "if(confirm('here the message')==false)return false;");
}
}
I tried both lines of code within the IF Statement (which is checking if what the user typed in the RadComboBox exists or not, if it doesn't return any items, then show a message), but none of them seem to work. I tried the same in debug mode and set a Breakpoint on the line within the IF statement, it actually DOES execute but I cannot see the alert.
I have just done something similar to this and my solution seems to be working pretty well.
Basically in ItemsRequested, once I know that no matches are found, I add a RadComboBoxItem manually. Give it a meaningful text such as "Add a new product..." and give it a distinct style as well to differentiate it from actual results.
Something like this:
protected void Product_PKRadComboBox_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
if (e.EndOfItems && e.NumberOfItems==0)
{
var addItem = new RadComboBoxItem("Add a new product...", "addnewproduct");
addItem.ToolTip = "Click to create a new product...";
addItem.CssClass = "UseSpecialCSSStyling";
Product_PKRadComboBox.Items.Add(addItem);
}
}
You then need to handle the SelectedIndexChanged event when the "addnewproduct" item is selected. Make sure to set the combobox's AutoPostBack="true".
protected void Product_PKRadComboBox_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
if (!string.IsNullOrEmpty(e.Value) && e.Value.Equals("addnewproduct"))
{
// do whatever you have to do to add a new product
}
}
You can use a RadWindow to show a confirmation box that says "Are you sure you want to add a new product?" with Yes and Cancel buttons. Go a step further by displaying the search text that the user typed in in a textbox within the RadWindow. This way the user can modify the text before adding the new item.
For example the user may type "water bottle" to search for a product. No results found so the user click on the "Add a new product..." item. The confirmation box shows up, then the user can change "water bottle" to "Green Durable Water Bottle 600ml" before clicking Yes to actually add the product.
Related
i like to get initial value to my DDL and write ddl1.Text="6" - it works fine..
i try to do the same to a DDL which is part of a simple usercontrol(3 DDLs which create a date) - this doesn't work!!!
in default.aspx i tried-
DateUserControl2.SetD("17");
DateUserControl2.SetM("7");
((DropDownList)DateUserControl2.Controls[4]).Text = "2003";
in DateUserControl.ascx.cs
i put all the listitems created in Page_Init and it works fine
the other methods
public void SetD(object d)
{
this.DropDownListDuc.Text = d + "";
}
public void SetM(object m)
{
this.DropDownListMuc.SelectedValue = m + "";
}
when i try to trace, i see that the methods are ok, but, for example,if d parameter is 4 and
this.DropDownListDuc.Text = 4 + "";
is performed, still NOTHING changes!!!
(again, the same line in a "simple" DDL,like DropDownList1.Text = "20"; changes the DDL to 20!!
changing a Label in the eser control works too. it is just a DDL_in_a_usercontrol problem
thanks!
Well, keep in mind that you are NOT allowed to have two controls with the same "id" on one page.
But, what then occurs if you drop the user control two times on the same web page?
I have a hotel edit UC.
So, I can do this:
Say this markup:
<uc1:UHotelEdit runat="server" ID="UHotelEdit"
MyTable ="tblHotelsA" />
<div style="clear:both;height:30px">
</div>
<uc1:UHotelEdit runat="server" ID="UHotelEdit2"
MyTable ="tblHotelsA" />
So, note we have TWO UC's on the page. UhotelEdit, and UhotelEdit2.
My page load code is this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
UHotelEdit.MyPk = 6;
UHotelEdit.LoadData();
UHotelEdit2.MyPk = 7;
UHotelEdit2.LoadData();
}
}
And now we have this:
So, in above, we have Hotel Name text box, first name, last name etc.
But, we are NOT allowed to have multiple "id" of the same control on the page.
So, how can/could I set the hotel name of the first control to Zoo, and Zoo2 for the 2nd one?
Well, all of the controls are "nested" inside of the UC.
This is quite much like a grid view, or whatever. So, you have two choices:
if several of the controls had to be "often" changed, then make a public property in the UC.
or, you can get/grab/pluck out the control name of the UC.
eg this:
protected void Button1_Click(object sender, EventArgs e)
{
TextBox txtHotel = UHotelEdit.FindControl("txtHotel") as TextBox;
TextBox txtHotel2 = UHotelEdit2.FindControl("txtHotel") as TextBox;
txtHotel.Text = "Zoo";
txtHotel2.Text = "Zoo2";
}
And thus we now have this:
But, if you had to "often" change the hotel name text box above?
Well, then add a public property to the UC, say like this:
public string HotelName
{
get { return txtHotel.Text; }
set { txtHotel.Text = value; }
}
And now our code becomes this:
protected void Button1_Click(object sender, EventArgs e)
{
UHotelEdit.HotelName = "Zoo";
UHotelEdit2.HotelName = "Zoo2";
}
So, for common or often controls to be changed? Setup a get/set for that control. For the rare and not common used?
Then you can use find control. Quite much you do the same to get a control out of repeater, listview, gridview etc. - you in general have to use find control for those nested controls.
Well, everything quite much works the same, but we have to prefix the control(s) with the name of the user control (id) we used when dropping on the page.
but, if you have JavaScript code, then how can I select the first one (hotel name) vs the 2nd one?
Turns out, all controls rendering inside of a UC will PREFIX the control with the name of the user control!!!
So, on the page you find two hotel text boxes,
UHotelEdit_txtHotel
UhotelEdit2_txtHotel
But, they are not exposed that way to code behind (just like controls nested in a listview or repeater also are not). but, they exist and jQuery selectors can be used against those controls.
In code behind, you have to use UC.findcontrol("txtHotel") to pluck out a reference to that control in the UC - since its nested inside.
So, if your UC has a dropdown list, and you want to with ease to change that value? Then add a PUBLIC method to the control that allows you do to this. So, while the controls inside are not exposed, you can with ease add a simple public method that allows you to change the drop down list value.
I've got a form that contains a listview which pulls in ticket info from a database. The database objects are all abstracted into a class library. There is a tabpage below the listview which displays various details of the tickets.
My problem is that I've implemented a search at the top of this form which isn't updating that tabpage, only the listview gets updated. After typing in keywords the listview refreshes properly and any items that dont' contain the keywords are removed until the text from the search box is cleared. But I can't get the tabpage to exhibit the same behavior. The tabpage still always contains all tickets.
For example, if I were to search for something where only 1 ticket was returned in the listview and say that ticket was the 10th ticket on record; the tabpage would show me details for the very first ticket. How can I get the tabpage to exhibit the same behavior as my listview after a search is made?
The tabpage currently gets filled with this function:
private void FillTicket()
{
try
{
if (listView1.SelectedIndices.Count > 0)
{
CTicket thistkt = comp.Tickets[listView1.SelectedIndices[0]];
dedit1.DocumentHTML = thistkt.LineItems.GetCombinedProblem();
dedit2.DocumentHTML = thistkt.LineItems.GetCombinedResolution();
lvAssignmentHistory.Items.Clear();
foreach (CInc_AssignmentHistory a in thistkt.AssignmentHistory)
{
ListViewItem itm = new ListViewItem();
itm.Text = a.pAsgn_Datetime.ToString();
itm.SubItems.Add(a.pAsgn_Group_fr);
itm.SubItems.Add(a.pAsgn_from);
itm.SubItems.Add(a.pAsgn_Group_to);
itm.SubItems.Add(a.pAsgn_to);
itm.SubItems.Add(a.pChanged_By);
lvAssignmentHistory.Items.Add(itm);
}
when this is called:
private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
//FillTicket();
if (txtBox_TicketSearch.Text != "")
{
FillTicketNothing();
}
else
{
FillTicket();
}
It seems to me you only update the tab page if the user selects different items in your ListView.
If your listView1_SelectedIndexChanged method is only a handler for the ListView.SelectedIndexChanged event, it is only called when the selection in listView1 changes, not when it's content is changed (without changing selection).
So you should call FillTicket when you changed the content of listView1.Items after your search.
Also, your FillTicket method only updates the tabpage if there are selected items in your ListView:
if (listView1.SelectedIndices.Count > 0)
I don't know if there is an else-branch for that if. If not, there will nothing change on your tab page if no items were selected. You may want to use listView1.Items.Count.
I need to unselect radio button in radio button list, i know it is more sensible to use checkbox but the management wants radio button to be unchecked.
RadioButtonList control is a collection of ListItems. To clear one radio button in the control you need to use Index for that particular item. To clear all radio buttons in the control, there is a method "ClearSelection()".
//To Unselect First Item
RadioButtonList1.Items[0].Selected = false;
//To unselect all Items
RadioButtonList1.ClearSelection();
hope this will resolve your issue.
private void Clear()
{
if(RadioButton1.Checked)
{
RadioButton1.Checked = false;
}
}
Use this:
RadioButton1.Checked = false;
myRadioButtonList.SelectedIndex = -1;
Hope this help.
You mean you want it to be possible for your radio button group to have zero values selected? Technically, you can just ensure that no radio in the group has its checked value set. checked="" or just delete the entire attribute.
Be aware that this is an invalid state for the radio group. It's like a boolean that is set to neither true nor false. It makes no sense semantically and is in violation of the HTML spec.
If you are constrained to a radio group, the only valid option is to include one radio that represents a 'none of the other options' state.
I had the same problem. In my case, I was using the radio button checkedChanged event to automatically append a medical documentation string snippet into a rich text box control. The snippet would be different for each radio button selected, and the requirement was that only one choice could be allowed. So radio buttons were the best choice instead of check boxes. The problem was that if the user wanted to remove ALL of the text snippets from the textbox, the s/he could just manually select the text from the box and delete it -- but at least one radio button would remain selected.
So, I found that the easiest way to fix this would be to add a button to the form and use its _Click event to set the specified radio button checked status to false.
So, My code looked like this...
// for rad 1
private void rad_NoDifferent_CheckedChanged(object sender, EventArgs e) {
if(rad_NoDifferent.Checked) {
rtb_GSC_Notes.AppendText(sRating_NoDiffMsg);
} else {
rtb_GSC_Notes.Text = rtb_GSC_Notes.Text.Replace(sRating_NoDiffMsg, sNoMsg.TrimEnd());
}
}
// for rad 2
private void rad_VeryDifferent_CheckedChanged(object sender, EventArgs e) {
if(rad_VeryDifferent.Checked) {
rtb_GSC_Notes.AppendText(sRating_VeryDiffMsg);
} else {
rtb_GSC_Notes.Text = rtb_GSC_Notes.Text.Replace(sRating_VeryDiffMsg, sNoMsg.TrimEnd());
}
}
// for rad 3
private void rad_Unsure_CheckedChanged(object sender, EventArgs e) {
if(rad_Unsure.Checked) {
rtb_GSC_Notes.AppendText(sRating_UnsureMsg);
} else {
rtb_GSC_Notes.Text = rtb_GSC_Notes.Text.Replace(sRating_UnsureMsg, sNoMsg.TrimEnd());
}
}
// for button reset
private void btn_ClearRadioButtons_Click(object sender, EventArgs e) {
rad_NoDifferent.Checked = false;
rad_Unsure.Checked = false;
rad_VeryDifferent.Checked = false;
}
Recently I was facing same issue however I found the solution with Radio button.
below are the aspx code for radio button
<div>
<asp:RadioButton ID="RadioButton1" GroupName="myg" onClick="clicked(this.id);" runat="server" />
<asp:RadioButton ID="RadioButton2" GroupName="myg" onClick="clicked(this.id);" runat="server" />
<asp:RadioButton ID="RadioButton3" GroupName="myg" onClick="clicked(this.id);" runat="server" />
<asp:RadioButton ID="RadioButton4" GroupName="myg" onClick="clicked(this.id);" runat="server" />
</div>
Just write below java script.
<script type="type/javascript">
var arr = [];
function clicked(radid) {
var ra = document.getElementById(radid);
if (arr.indexOf(radid) < 0) {
arr.splice(0, arr.length);
arr.push(radid);
}
else {
arr.splice(0, arr.length);
ra.checked = false;
}
}
</script>
Hope this will solve your purpose.
WPF/C#
if (RadioBTN.IsChecked == true) {
RadioBTN.IsChecked = false;
}
Problem:
I have 5 nodes in Treeview list including child nodes. Whenever I select one node it should display the name of the node in the combo box automatically without the need of pressing a button.
When I use ONselectednodechanged event it only fires once. So when I click on the node for the first time it fires the event but it does not do anything after that.
Could someone please give me some suggestions on what to do. I want it to automatically display the name of the node in the combo box when I click on it.
c#, ASP.net
Here is what I wrote so far:
protected void nav_tree_items_SelectedNodeChanged(object sender, EventArgs e)
{
if (nav_view_add.Visible == true)
{
panel_helper.GroupingText = "Add";
nav_multi.SetActiveView(nav_view_add); //set active view
nav_btn_save_add.CausesValidation = true;
DataRow[] row1 = TableClass.MainTable.Select("ItemId = " + nav_tree_items.SelectedValue);
nav_dd_parent.SelectedValue = row1[0]["ItemId"].ToString().Trim();
}
When the program is executed it does not even make the panel visible.
<asp:TreeView ID="nav_tree_items" runat="server" Height="100%" ShowLines="True"
Width="123%" onselectednodechanged="nav_tree_items_SelectedNodeChanged">
<HoverNodeStyle CssClass="hoverTreeItem" />
When I work with TreeView, I use the "AfterSelect" event. The stub can be easily generated by double clicking the TreeView control in [Design] mode. You can then do something like the following, using the data however you wish (MessageBox is just an example).
private void naviTree_AfterSelect(object sender, TreeViewEventArgs e)
{
MessageBox.Show("The node you just selected is [" + e.Node.ToString() + "]");
}
Hope this helps at all.
I have gridview which has columns of data and a button below the "Apply" to perform some action.
One column in Gridview is a checkbox column. When you select checkboxes and click apply a confirm message pops up asking "Are you sure?" with option of "Yes" and "No".
But if no check box is checked i want to show a popup to user to select a checkbox before performing an action and not show the confirm message popup.
What i have now is if no checkbox is selected the confirm message pops up first and if i press "yes" then an alert message pops up to select atleast one checkbox. If i press cancel no pop up shows.
Here is my code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ApplyAction_Button.Attributes.Add("onclick", "return confirm('Are you sure?');");
}
}
protected void ApplyAction_Button_Click(object sender, EventArgs e)
{
// Gets the selected checkboxes in the gridview
ArrayList selectedMachines = new ArrayList();
GetSelectedMachineIds(selectedMachines);
if (selectedMachines.Count == 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('Please select a machine for the action to be applied');</script>");
return;
}
// Action to be applied
}
I am trying to avoid the use of postback.
Another question:
Is there a server side confirm message box in asp.net?
Any help will be appreciated. Thanks
You can set your button visible to false, once check box is checked then you can show the button.
another way is to use javascript to check if checkbox is checked
code behind
ApplyAction_Button.Attributes.Add("onclick", "ShowConfirm();");
javascript
function ShowConfirm()
{
//check if checkbox is checked if is checked then display confirm message else display alert message
if( "assumed checkbox is checked"){
return confirm("message here");
}
else{
alert("message here");
}
}
try to see this thread
Checkbox in gridview
Determining a which checkbox is checked on a datagrid and updating DB
Regards