I have a devexpress calendar. The calendar has built in functions for grouping calendar by resource(which is location in my case). SO, I wrote my logic for making the calendar group by class name and provider too. The two work good individually. But when i was trying to place a radiobutton list so that user can select the way he want to group calendar,i had a problem.
This my radio button list and code behind event handler for it:
protected void filtertype_changed(object sender, EventArgs e)
{
if (filtertype.SelectedValue == "None")
{
// ASPxScheduler1.AppointmentDataSource = LoadAppointments();
classList.Visible = false;
providerslist.Visible = false;
classList.SelectedIndex = 0;
classList.SelectedIndex = 0;
//classList.SelectedValue = "0";
//providerslist.SelectedValue = "0";
ASPxScheduler1.GroupType = DevExpress.XtraScheduler.SchedulerGroupType.None;
}
else if (filtertype.SelectedValue == "Location")
{
// ASPxScheduler1.Dispose();
classList.Visible = false;
providerslist.Visible = false;
ASPxScheduler1.GroupType =
DevExpress.XtraScheduler.SchedulerGroupType.Resource;
}
else
{
ASPxScheduler1.GroupType = DevExpress.XtraScheduler.SchedulerGroupType.None;
classList.Visible = true;
providerslist.Visible = true;
}
}
This is my mark up for radio button
<asp:RadioButtonList ID="filtertype" runat="server"
OnSelectedIndexChanged="filtertype_changed" AutoPostBack="true" >
<asp:ListItem selected="true" Text="None" Value="None"></asp:ListItem>
<asp:ListItem Text="Location" Value="Location"></asp:ListItem>
<asp:ListItem>class Name and Provider</asp:ListItem>
</asp:RadioButtonList>
<asp:DropDownList ID="classList" runat="server" AutoPostBack="true"
Visible="false" ></asp:DropDownList>
<asp:DropDownList ID="providerslist" runat="server" AutoPostBack="true" Visible="false"
></asp:DropDownList>
classList and Provider List are the dropdownlists. So, what happens is when I change from Class and Provider radio button to location or none radio button, the calendar wont get refreshed and stores the values as per the dropdownlist and groups the calendar by location for those values only. So, once I change from classname and providers, I need to clear the dropdownlist values to 0(no item just white space). Can u just let me know how i can do this?
Throwing out the obvious here, but what about?:
DropDownList1.ClearSelection();
DropDownList1.Items.Clear();
Related
I have this dropdownlist in an ASP.NET page:
<asp:DropDownList ID="lstField1" runat="server">
<!--#include virtual="../path/to/myListOfValues.asp"-->
</asp:DropDownList>
Contents of "myListOfValues.asp" file:
<asp:ListItem value="%">Select value</asp:ListItem>
<asp:ListItem value="1">Value #1</asp:ListItem>
<asp:ListItem value="2">Value #2</asp:ListItem>
<asp:ListItem value="3">Value #3</asp:ListItem>
<asp:ListItem value="4">Value #4</asp:ListItem>
At some point of the page's execution, I change the items of this dropdownlist. But, eventually, i need to reload the items from the .asp file.
is there any way to "restore" the items from the .asp file, i.e. changing the dropdownlist's "innerHTML" or something like that?
Thanks in advance.
EDIT
I found a way:
1) Having a delimited string with the values i need to exclude from the items.
2) Splitting the delimited string
3) Looping the resultant array, and
4) Searching for the value in the dropdownlist. If the value is found, I disable it.
Something just like this:
'split the excluded items list
Dim arrExcludedItems() As String = myExcludedList.Split("|")
'enable all the dropdownlist's items.
For i As Integer = 0 To Me.lstField1.Items.Count - 1
Me.lstField1.Items(i).Enabled = True
Next
'search for the excluded item in the dropdownlist
'if it's found, disable the respective item.
For i As Integer = 0 To UBound(arrExcludedItems)
Me.lstField1.Items.FindByValue(arrExcludedItems(i)).Enabled = False
Next
Hope it helps for anyone.
Best regards,
I did some testing. I could not figure out how to rebind data from an asp file. But that does not mean you cannot achieve what you want. This snippet stores the original ListItems in ViewState so that you can bind the orignal ones later on.
<asp:DropDownList ID="lstField1" runat="server">
<!--#include virtual="/myListOfValues.asp"-->
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Bind new data" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Bind original data" OnClick="Button2_Click" />
Code behind
protected void Button1_Click(object sender, EventArgs e)
{
//create a new list to hold the original listitems
var list = new List<KeyValuePair<string, string>>();
//loop all the listitems and add them to the list
foreach (ListItem item in lstField1.Items)
{
list.Add(new KeyValuePair<string, string>(item.Value, item.Text));
Response.Write(item.Text);
}
//add the list to viewstate for later usage
ViewState["tempList"] = list;
//clear the list of its current items
lstField1.Items.Clear();
//add the new items to the dropdownlist
lstField1.Items.Add(new ListItem() { Text = "Item 1", Value = "1" });
lstField1.Items.Add(new ListItem() { Text = "Item 2", Value = "2" });
}
protected void Button2_Click(object sender, EventArgs e)
{
//load the list from viewstate and cast it back to a keyvalue list
var list = ViewState["tempList"] as List<KeyValuePair<string, string>>;
//clear the list of its current items
lstField1.Items.Clear();
//add the original items to the dropdownlist
foreach (var item in list)
{
lstField1.Items.Add(new ListItem() { Text = item.Value, Value = item.Key });
}
}
On page load the default value of the dropdownlist tell the user to select posible values.
Which is either Male or Female.If user did not select either of these values:Male or Female, the Genereate PatientNumber button should be disabled.
Otherwise the patient gender is generated base on the values select.
Currently if the dropdown is at default value i still can generate patientNumber.
Some one help me the cause of the error.i prefer the correct code.
protected void patient_num_Click(object sender, EventArgs e)
{
String gender = drl_gender.Text.ToString();
string patientNumber = " ";
RegistrationNumber Register_patient = new RegistrationNumber();
patient_num.Enabled = false;
if (gender=="Select Gender")
{
patient_num.Enabled = false;
}
else if (gender=="Male")
{
patient_num.Enabled = true;
patientNumber = Register_patient.GeneratePatientNumber(Gender.Male).ToString();
patientNumber = patientNumber.Replace("/", "-");
txtpatientNum.Text = patientNumber;
}
else
{
patient_num.Enabled = true;
patientNumber = Register_patient.GeneratePatientNumber(Gender.Female).ToString();
patientNumber = patientNumber.Replace("/", "-");
txtpatientNum.Text = patientNumber;
}
}
The problem in your code is that you are using the Text property of the DropDownList to determine what the user has selected(use SelectedValue instead). The Text property returns the text of the currently selected item but "" if no item is selected:
MSDN:
The Text property gets and sets the same value that the SelectedValuee
property does. The SelectedValue property is commonly used to
determine the value of the selected item in the ListControl control.
If no item is selected, an empty string ("") is returned.
Now have a look at your code(remember String.Empty when nothing is selected):
if (gender=="Select Gender")
{
patient_num.Enabled = false;
}
....
else
{
patient_num.Enabled = true;
// here we are!
patientNumber = Register_patient.GeneratePatientNumber(Gender.Female).ToString();
patientNumber = patientNumber.Replace("/", "-");
txtpatientNum.Text = patientNumber;
}
The solution:
Use a RequiredFieldValidator instead to ensure that the user has selected a gender. You can use the InitialValue property to tell it the value for your "-- please select --" item.
<asp:DropDownList id="DdlGender" runat="server" >
<asp:ListItem Text="-- please select --" Value="-1"></asp:ListItem>
<asp:ListItem Text="female" Value="1"></asp:ListItem>
<asp:ListItem Text="male" Value="2"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator id="RequiredGender"
InitialValue="-1"
ControlToValidate="DdlGender"
ErrorMessage="Please select gender!"
runat="server"/>
I would switch your logic over so that you explicity check for Male, Female then else.
if (gender=="Male")
{
...
}
else if (gender=="Female")
{
...
}
else
{
...
}
To answer your actual question, the value of your dropdown list probably isn't right. Maybe it's the casing or a stray character space. You could try something like
String gender = drl_gender.Text.Trim().ToLower();
and check for lowercase male, female. Put a break point on the line or add a watch and see what the actual value is.
What you want to do is set the button to disabled by default.
Then you should have an event hooked to the DropDownList:
protected void DropDownList_IndexChanged(object sender, EventArgs e)
{
var dd = (DropDownList) sender;
patient_num.Enabled = dd.SelectedIndex > 0;
}
I'm working on a DevExpress Gridview and I want to get the data of the selected row (only one row can be selected at the time). I'm working on the Server-Side and I'm using FocusedRowChanged function.
EDIT: The FocusedRowChanged fire but nothing happen and the textboxes do not change value
protected void dxgrDepartement_FocusedRowChanged(object sender, EventArgs e)
{
Page.ClientScript.RegisterClientScriptBlock(GetType(), "FetchData", "<script language='javascript'>FetchData('4654654646')</script>");
txtDescription.Text = "patate";
//txtComments.Text = dxgrDepartement.GetRowValues(dxgrDepartement.FocusedRowIndex, "IdDepartment").ToString();
}
And the "FetchData :
function FetchData(text) {
//ClearField();
document.getElementById("<%= txtDescription.ClientID %>").value = text.toString();
}
BTW - Changing the callbacks property made no difference for us. We needed callbacks for other functionality so couldn't turn this off anyway.
The GetRowValues method did not work either.
This is a technique described on DevExpress' web site and it worked for us as long as we didnt use DevExpress' controls (ASPxDateEdit, ASPxTextBox):
ASPX page:
<dxwgv:GridViewDataTextColumn Caption="Dist. %" FieldName="DistributionPerc" VisibleIndex="3"
Width="50px">
<DataItemTemplate>
<asp:TextBox ID="txtDistPerc" runat="server" Text='<%# Eval("DistributionPercent") %>'
Width="50px" />
</DataItemTemplate>
</dxwgv:GridViewDataTextColumn>
Code behind:
for (int i = 0; i < grdHistory.VisibleRowCount; i++)
{
TextBox textbox = grdHistory.FindRowCellTemplateControl(i, grdHistory.Columns["DistributionPerc"] as GridViewDataColumn, "txtDistPerc") as TextBox;
var anything = textbox.Text;
}
Use:
gridView.GetRowValues(gridView.FocusedRowIndex, columnFieldName1, columnFieldName2, ..., columnFieldNameN)
Method ASPxGridView.GetRowValues
Property ASPxGridView.FocusedRowIndex
grid.EnableCallback = false; solved my problems!
I have this code
<asp:RadioButtonList ID="rblSplitWeek" runat="server">
<asp:ListItem selected="true">No Choice</asp:ListItem>
<asp:ListItem Text = "First" Value = "Session('s_price_1')"></asp:ListItem>
<asp:ListItem Text = "Second"></asp:ListItem>
</asp:RadioButtonList>
But keep getting an error when trying to put the session variable in
Many thanks
Jamie
Unfortunately, data binding syntax (<%# %>) is not supported in this context, and literal binding syntax (<%= %> or <%: %>) do not produce the desired results when assigning values to server controls.
Here are a few alternate approaches:
1. Bind to a data source:
If you created a collection of objects containing text and value, you could easily set the DataSource, DataTextField, and DataValueField properties of the radio button list. Because the data source would be populated in code-behind, access to session variables is trivial.
For example, in markup:
<asp:RadioButtonList ID="rblSplitWeek" runat="server"
DataTextField="Text"
DataValueField="Value" />
And in code-behind:
public class RadioValue
{
public string Text { get; set; }
public string Value { get; set; }
}
// ...
var values = new RadioValue[]
{
new RadioValue { Text = "No Choice" },
new RadioValue { Text = "First", Value = Session["s_price_1"].ToString() },
new RadioValue { Text = "Second" }
}
rblSplitWeek.DataSource = values;
rblSplitWeek.DataBind();
2. Assign the value from code-behind
If you declare the list item with text but without value, you can set the value from script.
For example, in markup:
<asp:RadioButtonList ID="rblSplitWeek" runat="server">
<asp:ListItem selected="true">No Choice</asp:ListItem>
<asp:ListItem Text = "First" />
<asp:ListItem Text = "Second" />
</asp:RadioButtonList>
And in code-behind:
rblSplitWeek.Items.FindByText("First").Value = Session["s_price_1"].ToString();
I know this is way late, but another alternative is to load the RadioButtonList's SelectedIndex property in the PageLoad() event. Then you don't have to have a small RadioValue class - which is fine of course. Here is how I did it the last time... and yes I have used the RadioValue class way too.... but here it is using your radiobuttonlist without the RadioValue class:
protected void Page_Load(object sender, EventArgs e)
{
//Reload the last radio button selected.
if (Session["rblSplitWeekIndex"] != null)
{
rblSplitWeek.SelectedIndex = ((int)Session["rblSplitWeekIndex"]);
}
...
I save my radio button list selected index in a MasterPage which has a search scope radio button list and a search text box. So since a MasterPage killed my radio button list (and also the text which is not shown here), I had to load it when needed. Hope this helps!
Hiya i'm creating a web form and i want a user to be able to make certain selections and then add the selections to a text box or listbox.
Basically i want them to be able to type someone name in a text box ... check some check boxes and for it up date either a text for or a list box with the result on button click...
e.g.
John Smith Check1 Check3 Check5
any help would be great .. thanks
I will show you a basic example of a TextBox, Button and a ListBox. When the button is clicked the text will be added to the listbox.
// in your .aspx file
<asp:TextBox ID="yourTextBox" runat="server" /><br />
<asp:Button ID="yourButton" runat="server" Text="Add" OnClick="yourButton_Click" /><br />
<asp:ListBox ID="yourListBox" runat="server" /><br />
// in your codebehind .cs file
protected void yourButton_Click(object sender, EventArgs e)
{
yourListBox.Items.Add(yourTextBox.Text);
}
If you want to use javascript / jquery to do this your could just omit the server side event and just add the following function to the Click property of the button.
$(document).ready(function()
{
$("#yourButton").click(function()
{
$("#yourListBox").append(
new Option($('input[name=yourTextBox]').val(),
'Add value here if you need a value'));
});
});
Lets Suppose you have a gridview which is being populated on Searching happened using Textbox.
Gridivew got some checkboxes and after selection of these checkboxes you wanted to add into listbox
Here is the javascript which will help you to add into listbox.
Please modify as per your requirement,I have less time giving you only a javascript.
function addItmList(idv,valItem) {
var list =document.getElementById('ctl00_ContentPlaceHolder1_MyList');
//var generatedName = "newItem" + ( list.options.length + 1 );
list.Add(idv,valItem);
}
function checkitemvalues()
{
var gvET = document.getElementById("ctl00_ContentPlaceHolder1_grd");
var target = document.getElementById('ctl00_ContentPlaceHolder1_lstIControl');
var newOption = window.document.createElement('OPTION');
var rCount = gvET.rows.length;
var rowIdx = 0;
var tcount = 1;
for (rowIdx; rowIdx<=rCount-1; rowIdx++) {
var rowElement = gvET.rows[rowIdx];
var chkBox = rowElement.cells[0].firstChild;
var cod = rowElement.cells[1].innerText;
var desc = rowElement.cells[2].innerText;
if (chkBox.checked == true){
addItmList(rowElement.cells[1].innerText,rowElement.cells[2].innerText);
}
}
}