try
{
DataRowView drv = attDataGrid.SelectedItem as DataRowView;
att_id = Convert.ToInt32(drv.Row[0].ToString());
attComboBox.SelectedItem = drv.Row[1].ToString();
rdata = drv.Row[2].ToString(); ;
attDetail.Text = drv.Row[4].ToString();
DateTime sdt = dc.changeDateG(drv.Row[3].ToString());
if(rdata.Equals("حاضر"))
{
attPre.Checked = true;
}
else {
attUp.Checked = true;
}
try
{
attDate.SelectedDate = sdt;
}
catch (FormatException)
{
MessageBox.Show(sdt.ToString());
}
}
catch(NullReferenceException)
{
}
I am trying to set my attPre radio button checked but visual studio takes it as error any idea how to deal with this error???
Probably because you doing comparision not assignment
Use this:
attPre.Checked = true;
Instead of
attPre.Checked == true;
I have found out how to deal with it
RadioButton pr = attPre as RadioButton;
pr.IsChecked = true;
Related
i`m trying to find a efficient way to define conditions for radio-buttons.
After selecting a Radio-Button i should disable or fill the text-boxes. Following an example:
private void Transportauftrag_CheckedChanged(object sender, EventArgs e)
{
groupBox1.Visible = true;
groupBox8.Visible = false;
StartGerät.Text = "";
StartBlockFach.Text = "";
StartTiefe.Text = "";
ZielGerät.Text = "";
ZielBlockFach.Text = "";
ZielTiefe.Text = "";
FehlerFehler.Text = "****";
FehlerBereich.Text = "****";
FehlerInfo.Text = "****";
Transportbefehl.Text = "";
Breite.Text = "";
Tiefe.Text = "";
Höhe.Text = "";
Typ.Text = "";
Folgeauftrag.Text = "";
Behälternummer.Text = "";
Reserve.Text = "";
StartGerät.Enabled = true;
StartBlockFach.Enabled = true;
StartTiefe.Enabled = true;
ZielGerät.Enabled = true;
ZielBlockFach.Enabled = true;
ZielTiefe.Enabled = true;
FehlerFehler.Enabled = false;
FehlerBereich.Enabled = false;
FehlerInfo.Enabled = false;
Transportbefehl.Enabled = true;
Breite.Enabled = true;
Tiefe.Enabled = true;
Höhe.Enabled = true;
Typ.Enabled = true;
Folgeauftrag.Enabled = true;
Behälternummer.Enabled = true;
Reserve.Enabled = true;
}
So now i should do this 7 times.
And for this i need over 400 Line of Codes in my WindowsFormsApp-File.
Are they any better way / solution to do this?
ok here are some suggestions. Basically if faced with such a problem then it indicates that you need an organizational structure. Otherwise one gets lost. As it appears from the picture of your GUI you already have GroupBoxes that organize this. All the labels and Textboxes inside that groupbox are in groupBox1.Controls. You can get them out in 1 blow even by type:
List<TextBox> allTextBoxesFromGroupBox1 = groupBox1.Controls.OfType<TextBox>().ToList();
Now you can iterate over it and write the same value for each Textbox:
foreach (TextBox tb in allTextBoxesFromGroupBox1)
{
tb.Text = "";
}
But you better make a method from it:
private void FillAllTextBoxes(GroupBox groupBox, string text)
{
List<TextBox> allTextBoxesFromGroupBox1 = groupBox.Controls.OfType<TextBox>().ToList();
foreach (TextBox tb in allTextBoxesFromGroupBox1)
{
tb.Text = "";
}
}
Now you can simply call it and pass the necessary input:
FillAllTextBoxes(groupBoxStart, "");
FillAllTextBoxes(groupBoxZiel, "");
FillAllTextBoxes(groupBoxFehler, "****");
FillAllTextBoxes(groupBoxParameter, "");
At this point we got rid of 17 Lines and introduced only 4
Proceeding... The next step would be the enabling of the controls. It seems that you treat again all Textboxes inside the same groupbox also the same. So we can introduce another parameter for the enabling part into the method:
private void FillAllTextBoxes(GroupBox groupBox, string text, bool enable)
{
List<TextBox> allTextBoxesFromGroupBox1 = groupBox.Controls.OfType<TextBox>().ToList();
foreach (TextBox tb in allTextBoxesFromGroupBox1)
{
tb.Text = "";
tb.Enabled = enable;
}
}
and this allows us to remove the rest of the lines entirely without introducing new lines of code:
FillAllTextBoxes(groupBoxStart, "", true);
FillAllTextBoxes(groupBoxZiel, "", true);
FillAllTextBoxes(groupBoxFehler, "****", false);
FillAllTextBoxes(groupBoxParameter, "", true);
So now you are down at 4 lines (I see only 4 groupboxes in your screenshot) of code
My question is exactly the same as this Pls. don't down vote as the thread did not have answers.
Problem in Brief:
I have an CustomGridView, a type of DataGridView. The below code is attached to it. When I drop the datagridview in design time I can see the columns are all in proper but except for the name of the datagridviewcolumn names are different and is not what I gave.
In runtime the Columns are duplicated. Could not figure out why.
Property Page looks like this
Code:
public class CustomAccountDataGridView : DataGridView
{
private bool _paddingOn = true;
public bool PaddingOn
{
get { return _paddingOn; }
set { _paddingOn = value; }
}
public CustomAccountDataGridView()
{
this.AutoGenerateColumns = false;
this.Columns.Clear();
DataGridViewTextBoxColumn columnAccountID = new DataGridViewTextBoxColumn();
columnAccountID.DataPropertyName = "ACCOUNTID";
columnAccountID.Name = "colACCOUNTID";
columnAccountID.HeaderText = "A/c";
columnAccountID.Width = 110;
columnAccountID.Visible = false;
this.Columns.Add(columnAccountID);
DataGridViewTextBoxColumn columnClientAccountID = new DataGridViewTextBoxColumn();
columnClientAccountID.DataPropertyName = "CLIENTACCOUNTID";
columnClientAccountID.Name = "colCLIENTACCOUNTID";
columnClientAccountID.HeaderText = "Client A/c";
columnClientAccountID.Width = 110;
this.Columns.Add(columnClientAccountID);
DataGridViewTextBoxColumn columnParticipantID = new DataGridViewTextBoxColumn();
columnParticipantID.DataPropertyName = "PARTICIPANTID";
columnParticipantID.Name = "colPARTICIPANTID";
columnParticipantID.HeaderText = "Participant";
columnParticipantID.Width = 60;
this.Columns.Add(columnParticipantID);
DataGridViewTextBoxColumn columnAccountName = new DataGridViewTextBoxColumn();
columnAccountName.Name = "colACCOUNTNAME";
columnAccountName.HeaderText = "A/c Name";
columnAccountName.Width = 200;
columnAccountName.ReadOnly = true;
this.Columns.Add(columnAccountName);
DataGridViewTextBoxColumn columnXsactValue = new DataGridViewTextBoxColumn();
columnXsactValue.DataPropertyName = "XSACTVALUE";
columnXsactValue.Name = "colXSACTVALUE";
columnXsactValue.Width = 110;
columnXsactValue.HeaderText = "Value";
columnXsactValue.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
columnXsactValue.DefaultCellStyle.Format = "N2";
this.Columns.Add(columnXsactValue);
}
protected override void OnDataBindingComplete(DataGridViewBindingCompleteEventArgs e)
{
string sClientID = string.Empty;
foreach (DataGridViewRow dvr in (this.Rows))
{
for (int i = 0; i < dvr.Cells.Count; i++)
{
if (this.Columns[i].DataPropertyName == "ACCOUNTID")
{
if (dvr.Cells["colACCOUNTID"].Value != null)
{
sClientID = dvr.Cells["colACCOUNTID"].Value.ToString();
dvr.Cells["colACCOUNTNAME"].Value = sClientID; //utility.ClientExtention.getAccountName(sClientID);
break;
}
}
}
}
base.OnDataBindingComplete(e);
}
protected override void OnEditingControlShowing(DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control.GetType() == typeof(DataGridViewTextBoxEditingControl))
{
(e.Control as TextBox).CharacterCasing = CharacterCasing.Upper;
}
base.OnEditingControlShowing(e);
}
protected override void OnCellValueChanged(DataGridViewCellEventArgs e)
{
string sClientAccountID = string.Empty;
string sParticipantID = "JKB";
if (e.RowIndex >= 0)
{
if (this.Columns[e.ColumnIndex].DataPropertyName == "CLIENTACCOUNTID")
{
if (this[e.ColumnIndex, e.RowIndex].Value != null)
{
if (this[e.ColumnIndex, e.RowIndex].Value.ToString().Length != 0)
{
if (this.PaddingOn)
{
sClientAccountID = this[e.ColumnIndex, e.RowIndex].Value.ToString().ToUpper().PadLeft(13, '0');
}
else
{
sClientAccountID = this[e.ColumnIndex, e.RowIndex].Value.ToString().ToUpper();
}
this[e.ColumnIndex, e.RowIndex].Value = sClientAccountID;
}
}
}
if (this.Columns[e.ColumnIndex].DataPropertyName == "PARTICIPANTID")
{
if (this[e.ColumnIndex, e.RowIndex].Value != null)
{
if (this[e.ColumnIndex, e.RowIndex].Value.ToString().Length != 0)
{
sParticipantID = this[e.ColumnIndex, e.RowIndex].Value.ToString().ToUpper();
}
this[e.ColumnIndex, e.RowIndex].Value = sParticipantID;
}
}
if (sClientAccountID != string.Empty & sParticipantID != string.Empty)
{
this["ACCOUNTNAME", e.RowIndex].Value = (string.Format("{0}-{1}", sParticipantID, sClientAccountID));
}
}
base.OnCellValueChanged(e);
}
}
}
I found something that seems to work here:
protected override void InitLayout()
{
base.InitLayout();
SetColumns();
}
SetColumns is the subroutine to add the columns I want.
In case it can be helpful, I have just encountered this problem, on VS 2015 Express, with a standard DataGridView. The problem appeared as soon as I renamed my custom columns. Reverting to default names fixed the problem, as much as flushing the custom columns and keeping the duplicates. I can reproduce and fix the problem anytime, it seems consistent. Note that when both original and duplicate columns are in, there is no trace of the duplicates in the designer code(Designer.cs), don't ask me why...
My code is working fine if the statement (numtickets > tickav) is true (if tickets available is greater than tickets ordered) But if other wise, it throws in this error "FormatException was unhandled by user code, Input string was not in a correct format" on int numTick = Convert.ToInt32(txtNumberOfTickets.Text);
I do know that somehow I can use tryparse, i need help putting it in the code.
Any help would be appreciated, thank you
namespace TicketsApp
{
public partial class TicketOrder : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["description"] != null && Session["EventID"] != null && Session["numtickets"] != null && Session["ticketcost"] != null
&& Session["State"] != null && Session["Section"] != null && Session["Row"] != null && Session["date"] != null)
{
if (!IsPostBack)
{
try
{
txtEventDescription.Text = Session["description"].ToString();
txtEventID.Text = Session["EventID"].ToString();
txtTicketsAvailable.Text = Session["numtickets"].ToString();
txtTicketCost.Text = Session["ticketcost"].ToString();
txtState.Text = Session["State"].ToString();
txtSectionNumber.Text = Session["Section"].ToString();
txtRowNumber.Text = Session["Row"].ToString();
txtNumberOfTickets.Focus();
lblOutput.Visible = false;
}
catch
{
lblError.Text = "Please Search for Tickets First!";
lblError.Visible = true;
btnOrderTickets.Visible = false;
Response.Redirect("TicketSearch.aspx");
return;
}
}
}
}
protected void btnOrderTickets_Click(object sender, EventArgs e)
{
TicketsDataAccessDataContext NewOrder = new TicketsDataAccessDataContext();
int numTick = Convert.ToInt32(txtNumberOfTickets.Text);
string s = txtTotalCost.Text.Substring(1);
int totc = Convert.ToInt32(s);
int id = Convert.ToInt32(txtEventID.Text);
DateTime dt = Convert.ToDateTime(Session["date"]);
int returnedValue = NewOrder.PlaceOrderFull(id, txtEventDescription.Text, dt, Session["State"].ToString(), Session["section"].ToString(), Session["Row"].ToString(), numTick, totc, "vfateev");
if (returnedValue != 0)
{
lblOutput.Text = "Error has occured. Please try again";
lblOutput.Visible = true;
btnOrderTickets.Visible = false;
}
else
{
lblOutput.Visible = true;
lblOutput.Text = "Thank you";
btnOrderTickets.Visible = false;
}
}
protected void txtNumberOfTickets_TextChanged1(object sender, EventArgs e)
{
int cos = Convert.ToInt32(txtTicketCost.Text);
int numtickets = Convert.ToInt32(txtNumberOfTickets.Text);
int tickav = Convert.ToInt32(txtTicketsAvailable.Text);
if (numtickets > tickav)
{
lblError.Text = "Please Enter a valid ticket quantity";
lblError.Visible = true;
lblOutput.Text = "";
txtNumberOfTickets.Text = "";
}
else
{
int cost = cos * numtickets + 5;
txtTotalCost.Text = "$" + cost.ToString();
lblOutput.Visible = false;
lblFee.Text = "There is a $5 shipping fee";
lblFee.Visible = true;
lblError.Text = "";}
}
}
}
You can use int.TryParse which returns a boolean and does not throw an exception.
int numTick = 0;
bool result = int.TryParse(txtNumberOfTickets.Text, out numTick );
You can also do some client side validation to ensure that the field is filled in and contains a number.
Here is one of your methods rewritten using Int32.TryParse. I assumed you're doing txtTotalCost.Substring(1) to trim off the currency symbol. There are probably safe ways to do this, I'm just going to trim "$" for this example.
protected void btnOrderTickets_Click(object sender, EventArgs e)
{
int numberOfTickets, ticketCost, eventId;
if(Int32.TryParse(txtNumberOfTickets.Text, out numberOfTickets) &&
Int32.TryParse(txtTotalCost.Text.TrimStart('$'), out ticketCost) &&
Int32.TryParse(txtEventID.Text, out eventId))
{
DateTime dt = Convert.ToDateTime(Session["date"]);
TicketsDataAccessDataContext NewOrder = new TicketsDataAccessDataContext();
int returnedValue = NewOrder.PlaceOrderFull(eventId, txtEventDescription.Text, dt, Session["State"].ToString(), Session["section"].ToString(), Session["Row"].ToString(), numberOfTickets, ticketCost, "vfateev");
if (returnedValue != 0)
{
lblOutput.Text = "Error has occured. Please try again";
lblOutput.Visible = true;
btnOrderTickets.Visible = false;
}
else
{
lblOutput.Visible = true;
lblOutput.Text = "Thank you";
btnOrderTickets.Visible = false;
}
}
else
{
lblOutput.Visible = true;
lblOutput.Text = "Some validation error message here...";
}
}
You will need to make similar modifications to txtNumberOfTickets_TextChanged1 to ensure the user has entered valid text.
simply use something like
To use IsNumeric in C#, add a reference to Microsoft.VisualBasic.dll then
if (Information.IsNumeric(value))
{
DoSomthing();
}
else
{
DoSomethingElse();
}
UPDATE
OPEN VISUAL STUDIO ==> YOUR PROJECT
Click on solution and add reference, choose Microsoft.VisualBasic.dll confrim the new reference will be add to your references into the project.
Go at the top of your page and declare the import statemnet for Microsoft.VisualBasic.dll alias
using Microsoft.VisualBasic.dll;
then where you need to check the value of your textbox
if (Information.IsNumeric(yourtextbox.text.trim()))
{
//case true alias your value is numeric
//do what you need here like assing value to a var or any
//else
}
else
{
//put your logic here in case result is false and value
//is not numeric
}
i am working on an software in which i want to clear each thing after doing achieving a specific task, like clearing all the fields, list view etc etc and i've to write the a lot of things to be cleared off, like the code of my new button is:
private void btnNew_Click(object sender, EventArgs e)
{
txtProductCode1.ReadOnly = false;
txtInvoiceNo.ReadOnly = false;
cmbCustoemerType.Enabled = false;
cmbCustomerName.Enabled = false;
button1.Enabled = true;
txtProductCode1.Text = null;
txtWageName.Text = null;
txtWageCost.Text = null;
btnFirst.Visible = false;
btnPrevious.Visible = false;
btnNext.Visible = false;
btnLast.Visible = false;
cmbProductName.Enabled = true;
txtQty.ReadOnly = false;
txtPercant.ReadOnly = false;
txtDiscount.ReadOnly = false;
cmbCustoemerType.Enabled = true;
cmbCustomerName.Enabled = true;
button5.Enabled = true;
btnDelete.Enabled = true;
dtp1.Enabled = true;
btnSave.Text = "&Save";
cmbCustoemerType.Text = null;
cmbCustomerName.Text = null;
txtInvoiceNo.Clear();
txtDiscount.Clear();
txtGrandTotal.Clear();
txtProductName.Clear();
txtSalePrice.Clear();
txtQty.Clear();
txtTotal.Clear();
txtExtraWages.Text = null;
lvExtraWages.Items.Clear();
lvTransaction.Items.Clear();
lblCount.Text = null;
lblNetTotal.Text = null;
txtPercant.Text = null;
txtInvoiceNo.Text = invoice.ToString();
}
is there any way to get rid of writing the code again n again, like i need to enable one thing which i've disabled here on another button so i have to write reverse code of this to achieve the task and it's really annoying! is there any other way to do this?
EDIT:
tried following code:
private void btnNew_Click(object sender, EventArgs e)
{
//using setboxdefault function
SetTextBoxDefaults();
cmbCustoemerType.Text = null;
cmbCustomerName.Text = null;
cmbCustoemerType.Enabled = false;
cmbCustomerName.Enabled = false;
cmbProductName.Enabled = true;
cmbCustoemerType.Enabled = true;
cmbCustomerName.Enabled = true;
button5.Enabled = true;
btnDelete.Enabled = true;
button1.Enabled = true;
btnFirst.Visible = false;
btnPrevious.Visible = false;
btnNext.Visible = false;
btnLast.Visible = false;
btnSave.Text = "&Save";
lvExtraWages.Items.Clear();
lvTransaction.Items.Clear();
lblCount.Text = null;
lblNetTotal.Text = null;
dtp1.Enabled = true;
txtInvoiceNo.Text = invoice.ToString();
}
private void SetTextBoxDefaults()
{
var textBoxes = GetControls(this, typeof(TextBox));
foreach (var textBox in textBoxes)
{
TextBox.Clear();
}
}
public IEnumerable<Control> GetControls(Control control, Type type)
{
var controls = control.Controls.Cast<Control>();
return controls.SelectMany(ctrl => GetControls(ctrl, type)).Concat(controls).Where(c => c.GetType() == type);
}
but it's giving error on TextBox.Clear(); , error is Error 4
An object reference is required for the non-static field, method, or property 'System.Windows.Forms.TextBoxBase.Clear()'
Please let me know where i am mistaking..!!
As Tim has suggested, you can iterate though the controls and set each one accordingly..
public IEnumerable<Control> GetControls(Control control,Type type)
{
var controls = control.Controls.Cast<Control>();
return controls.SelectMany(ctrl => GetControls(ctrl,type)).Concat(controls).Where(c => c.GetType() == type);
}
private void btnNew_Click(object sender, EventArgs e)
{
SetComboBoxDefaults();
SetTextBoxDefaults();
SetButtonDefaults();
}
private void SetComboBoxDefaults()
{
var comboBoxes = GetControls(this, typeof(ComboBox));
foreach (var comboBox in comboBoxes)
{
((ComboBox)comboBox).Enabled = false;
((ComboBox)comboBox).Text = null;
}
}
private void SetTextBoxDefaults()
{
var textBoxes = GetControls(this, typeof(TextBox));
foreach (var textBox in textBoxes)
{
((TextBox)textBox).Clear();
}
}
private void SetButtonDefaults()
{
var buttons = GetControls(this, typeof(Button));
foreach (var button in buttons)
{
((Button)button).Visible = false;
if (button.Name == "btnSave") ((Button)button).Text = "&Save";
}
}
You can also have separate GetControl methods so that it returns a specific type of Control, reducing the need to cast to derived types.
update for edit:
You are using the TextBox type instead of the variable name in the foreach loop. Update it to use textBox (lowercase), not TextBox (pascal) see below:
private void SetTextBoxDefaults()
{
var textBoxes = GetControls(this, typeof(TextBox));
foreach (var textBox in textBoxes)
{
((TextBox)textBox).Clear();
}
}
Remember to stay DRY
Don't
Repeat
Yourself
Partition the reset logic into suitable, small methods that reset a logical grouping of controls. Then invoke those methods where and as needed.
What I have done in several such cases is this:
void SetTextBoxReadOnly(bool val, param TextBox[] textBoxes)
{
if(textBoxes != null && textBoxes.Length > 0)
{
foreach(TextBox textBox in textBoxes)
{
if(textBox != null)
{
textBox.ReadOnly = val;
}
}
}
}
void SetControlEnabled(bool val, param Control[] ctrls)
{
if(ctrls != null && ctrls.Length > 0)
{
foreach(Control ctrl in ctrls)
{
if(ctrl != null)
{
ctrl.Enabled = val;
}
}
}
}
// etc set of methods for similar situations.
// there methods can be invoked as
...
...
...
SetTextBoxReadOnly(true, txtProductCode1,
txtInvoiceNo,
txtQty,
txtPercant,
txtDiscount);
I have an aspx page where i dynamically add a radiobuttonlist with OnSelectedIndexChanged event. In the event i check for the selected items. i have 2 items.
For the first item,the event is firing well, However if i choose the other option the event is not firing: below the code..
The event is only firing is i change from "Some provided" to "All provided" the other way it is not working
Adding the RBL:
RadioButtonList dControl_b = new RadioButtonList();
dControl_b.ID = "rbl_MinCriteria";
dControl_b.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
dControl_b.CssClass = "Font";
dControl_b.Font.Name = "Arial";
dControl_b.Font.Size = 8;
dControl_b.ToolTip = "";
dControl_b.SelectedIndex = -1;
dControl_b.SelectedIndexChanged += new EventHandler(rbl_MinCriteria_SelectedIndexChanged);
dControl_b.AutoPostBack = true;
Checking the selected item:
if(rbl_MinCriteria.SelectedItem.ToString() == "All provided")
{
cbl_MinimumCriteria.Items[0].Selected = true;
cbl_MinimumCriteria.Items[1].Selected = true;
cbl_MinimumCriteria.Items[2].Selected = true;
cbl_MinimumCriteria.Items[3].Selected = true;
cbl_MinimumCriteria.Enabled = false;
//*************************************************************
if (ddl_CountryOccurence.SelectedValue != "Please choose")
{
ddl_CountryOccurence.Enabled = false;
}
else
{
ddl_CountryOccurence.Enabled = true;
}
//*************************************************************
if (tb_DueDate.Text != "")
{
tb_DueDate.Enabled = false;
}
else
{
tb_DueDate.Enabled = true;
}
OtherControlI.Enabled = false;
OtherControlII.Enabled = false;
OtherControlIII.Enabled = false;
}
if (rbl_MinCriteria.SelectedItem.ToString() == "Some provided")
{
cbl_MinimumCriteria.Items[0].Selected = false;
cbl_MinimumCriteria.Items[1].Selected = false;
cbl_MinimumCriteria.Items[2].Selected = false;
cbl_MinimumCriteria.Items[3].Selected = false;
cbl_MinimumCriteria.Enabled = true;
//*************************************************************
if (ddl_CountryOccurence.SelectedValue != "Please choose")
{
ddl_CountryOccurence.Enabled = false;
}
else
{
ddl_CountryOccurence.Enabled = true;
}
//*************************************************************
if (tb_DueDate.Text != "")
{
tb_DueDate.Enabled = false;
}
else
{
tb_DueDate.Enabled = true;
}
OtherControlI.Enabled = false;
OtherControlI.SelectedIndex = -1;
OtherControlII.Enabled = false;
OtherControlII.SelectedIndex = -1;
OtherControlIII.Enabled = false;
OtherControlIII.SelectedIndex = -1;
}
Any help and Comment is much appreciated
This is for people who find this question from Google:
On the RadioButtonList, set the AutoPostBack property to true.
RadioButtonList OnSelectedIndexChanged
I have this problem and solved it.
For raising onselectedindexchanged event of RadioButtonList , check below items:
<asp:RadioButtonList ID="rdlCondition" runat="server" AutoPostBack="True"
onselectedindexchanged="rdlCondition_SelectedIndexChanged">
and in the Page_Load set them with code :
rdlCondition.AutoPostBack = true;
rdlCondition.SelectedIndexChanged += new EventHandler (rdlCondition_SelectedIndexChanged);
Looking at the code above there seems to be alot of code reuse. I reorganized your code a bit (assuming you didnt leave anything out). Keep in mind I never tested it.
protected void rbl_MinCriteria_SelectedIndexChanged(object sender,EventArgs e)
{
if (rbl_MinCriteria.SelectedIndex<0) return; //If nothing is selected then do nothing
OtherControlI.Enabled = false;
OtherControlII.Enabled = false;
OtherControlIII.Enabled = false;
if(rbl_MinCriteria.SelectedItem.ToString() == "All provided")
{
cbl_MinimumCriteria.Items[0].Selected = true;
cbl_MinimumCriteria.Items[1].Selected = true;
cbl_MinimumCriteria.Items[2].Selected = true;
cbl_MinimumCriteria.Items[3].Selected = true;
cbl_MinimumCriteria.Enabled = false;
}
if (rbl_MinCriteria.SelectedItem.ToString() == "Some provided")
{
cbl_MinimumCriteria.Items[0].Selected = false;
cbl_MinimumCriteria.Items[1].Selected = false;
cbl_MinimumCriteria.Items[2].Selected = false;
cbl_MinimumCriteria.Items[3].Selected = false;
cbl_MinimumCriteria.Enabled = true;
OtherControlI.SelectedIndex = -1;
OtherControlII.SelectedIndex = -1;
OtherControlIII.SelectedIndex = -1;
}
//*************************************************************
if (ddl_CountryOccurence.SelectedValue != "Please choose")
{
ddl_CountryOccurence.Enabled = false;
}
else
{
ddl_CountryOccurence.Enabled = true;
}
//*************************************************************
if (tb_DueDate.Text != "")
{
tb_DueDate.Enabled = false;
}
else
{
tb_DueDate.Enabled = true;
}
}
I know this doesn't help your current problem but this is just a suggestion. If you could post the code where your actually adding the values to the list I could help a bit more.
EDIT: Your problem could be your not setting the value of your items, only the text. Try using rbl_MinCriteria.SelectedItem.Text =="All provided" instead.
I've made a sample aspx page, and added one panel in .aspx like below:
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
And in code behind, I've added following code:
protected void Page_Load(object sender, EventArgs e)
{
RadioButtonList dControl_b = new RadioButtonList();
dControl_b.ID = "rbl_MinCriteria";
dControl_b.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
dControl_b.CssClass = "Font";
dControl_b.Font.Name = "Arial";
dControl_b.Font.Size = 8;
dControl_b.ToolTip = "";
dControl_b.SelectedIndex = -1;
dControl_b.SelectedIndexChanged += new EventHandler(rbl_MinCriteria_SelectedIndexChanged);
dControl_b.AutoPostBack = true;
dControl_b.Items.Add(new ListItem("All provided"));
dControl_b.Items.Add(new ListItem("Some provided"));
Panel1.Controls.Add(dControl_b);
}
protected void rbl_MinCriteria_SelectedIndexChanged(object sender,EventArgs e)
{
RadioButtonList rbl_MinCriteria = (RadioButtonList)Panel1.FindControl("rbl_MinCriteria");
if(rbl_MinCriteria.SelectedItem.ToString() == "All provided")
{
}
if (rbl_MinCriteria.SelectedItem.ToString() == "Some provided")
{
}
}
The event is FIRING EVERY TIME the radio button listitem is changed.
So, I'm afraid, you have done something wrong elsewhere. Good luck.