I have C1FlexGrid in my form with multiple rows. I want to select random rows and get those selected row value.
Selection Mode:
this.CliAcctHolderGrid.SelectionMode = C1.Win.C1FlexGrid.SelectionModeEnum.ListBox;
Function Code:
private void Submit(object sender, EventArgs e)
{
List<string> holderIdentificationId = new List<string>();
if (CliAcctHolderGrid.RowSel >= 1)
{
for (int CliAcctHolder = 1; CliAcctHolder <= CliAcctHolderGrid.Row; CliAcctHolder++)
{
C1.Win.C1FlexGrid.Row rowSel = CliAcctHolderGrid.Rows[CliAcctHolder];
holderIdentificationId.Add((string)rowSel["HolderIdentifierId"]);
}
}
}
From the code I have done, I am getting values which I didn't selected. Getting all values from the grid. Can anyone please suggest me where I am making a mistake.
private void Submit(object sender, EventArgs e)
{
List<string> holderIdentificationId = new List<string>();
if ( CliAcctHolderGrid.RowSel >= 1 )
{
foreach(C1.Win.C1FlexGrid.Row dr in CliAcctHolderGrid.Rows.Selected)
{
holderIdentificationId.Add( (string)dr["HolderIdentifierId"] );
}
}
}
Related
The thing I want to do is that i want to select 1,2 or 3 items from the listbox and save them into a session and then display them all on another form in a listbox.
Here's my code!
This is my first post on stack overflow, so no hate please <3
//WebForm1
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lstProducts.Items.Add("Soap");
lstProducts.Items.Add("Schampoo");
lstProducts.Items.Add("Conditioner");
}
}
protected void cmdBuy_Click(object sender, EventArgs e)
{
string[] products = new string[3];
for (int i = 0; i < lstProducts.Items.Count; ++i)
{
if (lstProducts.Items[i].Selected)
products[i] = lstProducts.Items[i].Text;
else
products[i] = "0";
}
Session["Cart"] = products;
}
protected void cmdCart_Click(object sender, EventArgs e)
{
if (Session["Cart"] != null)
{
Response.Redirect("WebForm2.aspx");
}
}
}
//WebForm2
protected void Page_Load(object sender, EventArgs e)
{
string[] products = (string[])Session["Cart"];
for (int i = 0; i < 3; ++i)
{
if (products[i] != "0")
{
lstCart.Items.Add(products[i]);
}
}
}
}
}
The thing is that I only get the last selected item to display in the listbox on form2???
Try this
To store all items of the of the list box, you can add that items in array as:
string[] a = new string[]{"item 1","item 2","item 3"};
Session["values"] = a;
And in the next page, you can retrieve it like this.
string[] a = (string[])Session["values"]
EDIT #1
your case you can do like
ArrayList al = new ArrayList();
for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected == true)
{
al.Add(ListBox1.Items[i].Value);
}
}
Session["selectedValues"] = al;
now you can use this sessiom variable in another page, but don't forget to cast in ArrayList type of object.
I'm trying to move selected items in list box1 to list box2, and vice versa. I have two buttons, >> and <<. When I select items in listbox1 and then click on >> the items should move from listbox1 to listbox2.
private void MoveListBoxItems(ListBox source, ListBox destination)
{
ListBox.SelectedObjectCollection sourceItems = source.SelectedItems;
foreach (var item in sourceItems)
{
destination.Items.Add(item);
}
while (source.SelectedItems.Count > 0)
{
source.Items.Remove(source.SelectedItems[0]);
}
}
private void button2_Click_1(object sender, EventArgs e)
{
MoveListBoxItems(listbox , lstActivity);
}
your code works fine. i tested it.
your question is "I try to move selected item in list box1 to list box2."
i think your button2 has problem.delete button2 and the code below
private void button2_Click_1(object sender, EventArgs e)
{
MoveListBoxItems(listbox , lstActivity);
}
then create other button and create click event.
full source:
private void MoveListBoxItems(ListBox source, ListBox destination)
{
ListBox.SelectedObjectCollection sourceItems = source.SelectedItems;
foreach (var item in sourceItems)
{
destination.Items.Add(item);
}
while (source.SelectedItems.Count > 0)
{
source.Items.Remove(source.SelectedItems[0]);
}
}
private void first2second_Click(object sender, EventArgs e)
{
MoveListBoxItems(FirstListbox, LastListbox);
}
private void second2first_Click(object sender, EventArgs e)
{
MoveListBoxItems(LastListbox, FirstListbox);
}
this code is work. if you want select more than one item change property
SelectionMode = MultiSimple;
private void buttonMoveToListBox1_Click(object sender, EventArgs e)
{
if(listBox1.SelectedIndex != -1)
{
listBox2.Items.Add(listBox1.SelectedValue);
listBox1.Items.Remove(listBox1.SelectedValue);
}
}
private void buttonMoveToListBox2_Click(object sender, EventArgs e)
{
if(listBox2.SelectedIndex != -1)
{
listBox1.Items.Add(listBox2.SelectedValue);
listBox2.Items.Remove(listBox2.SelectedValue);
}
}
There will be conflicts for every deleted row, so go with the below code:
>>
for (int intCount = ListBox1.SelectedItems.Count - 1; intCount >= 0; intCount--)
{
ListBox2.Items.Add(ListBox1.SelectedItems[intCount]);
ListBox1.Items.Remove(ListBox1.SelectedItems[intCount]);
}
<<
for (int intCount = ListBox2.SelectedItems.Count - 1; intCount >= 0; intCount--)
{
ListBox1.Items.Add(ListBox2.SelectedItems[intCount]);
ListBox2.Items.Remove(ListBox2.SelectedItems[intCount]);
}
If the above one doesn't work then try this:
while (ListBox1.SelectedItems.Count > 0)
{
ListBox2.Items.Add(ListBox1.SelectedItems[0].Text);
ListBox1.SelectedItems[0].Remove();
}
For more type of answers you can go with this link
Here Two ListBoxes. When i select the name from Left listbox and click ">>" Button the data move to Right ListBox
Code..
currentItemText = LeftListBox.SelectedValue.ToString();
currentItemIndex = LeftListBox.SelectedIndex;
RightListBox.Items.Add(currentItemText);
if (myDataList != null)
{
myDataList.RemoveAt(currentItemIndex);
}
ApplyDataBinding();
I solved using this code:
private void MoveListBoxItems(ListBox poSource, ListBox poDestination)
{
while (poSource.SelectedItems.Count > 0)
{
poDestination.Items.Add(poSource.SelectedItems[0]);
poSource.Items.Remove(poSource.SelectedItems[0]);
}
}
<script type="text/javascript">
$(document).ready(function() {
// > arrow
$('#SingleRightMove').click(function() {
$('#fromBox option:selected').remove().appendTo('#toBox');
//$("#tobox option").attr("selected", false);
$('#toBox').find("option").attr("selected", false);
});
// < arrow
$('#SingleLeftMove').click(function() {
$('#toBox option:selected').remove().appendTo('#fromBox');
$("#fromBox option").attr("selected", false);
});
// >> arrow
$('#AllRightMove').click(function() {
$('#fromBox option').remove().appendTo('#toBox');
$("#toBox option").attr("selected", false);
});
// << arrow
$('#AllLeftMove').click(function() {
$('#toBox option').remove().appendTo('#fromBox');
$("#fromBox option").attr("selected", false);
});
});
</script>
Get the >> and << buttons created with 2 list boxes like listbox2 and 3 below...get ur items in list box 2 first by something like get-content or get-adcomputer etc..
$buttonMOVERight_Click={
foreach ($Srv in $listbox2.selectedItems)
{$selectedServers=$Srv}
$listbox3.BeginUpdate()
foreach($TSrv in $Srv)
{$listbox3.Items.Add($TSrv);
$listbox2.Items.Remove($TSrv);}
$listbox3.EndUpdate()
}
$buttonMoveLeft_Click={
#TODO: Place custom script here
foreach ($Srvs in $listbox3.selectedItems)
{$ServersinRt=$Srvs}
$listbox2.BeginUpdate()
foreach($rSRv in $Srvs)
{$listbox2.Items.Add($rSRv);
$listbox3.Items.Remove($Srvs);}
$listbox2.EndUpdate()
}
I want to display the number say 1 to 100 by selecting a item in drop down list. I mean, if I select 4 times, it should count as 4 and display.
I have tried the code below, but it is not working.
//Method
public void cl()
{
if (Catddl.SelectedIndex != 0)
{
for (int i = 1; i <= 100; i++)
{
Label12.Text = Convert.ToString(i);
}
}
}
//called the method
protected void Catddl_SelectedIndexChanged(object sender, EventArgs e)
{
cl();
}
I worked on your problem and this is the result.It works fine for me.Hope it also work for you.
static int count = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
private void bind()
{
ArrayList ar = new ArrayList();
ar.Add("first");
ar.Add("Second");
ar.Add("Third");
ar.Add("Four");
ar.Add("Five");
ar.Add("Six");
ar.Add("Seven");
DropDownList1.DataSource = ar;
DropDownList1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//string str = DropDownList1.SelectedValue;
if (count == 0)
count = 1;
Label1.Text = count++.ToString();
}
Still if you have any doubt then ask.
If you are trying to count how many times the user selects something from a drop down list, you can do:
int counter = 0;
private void Catddl_SelectedIndexChanged(object sender, EventArgs e)
{
counter++;
Label12.Text = counter.ToString();
}
I am not sure if the title of my question is in sync with the content of my question.
I have a dropdown list with the datasource being list List<int> numbers;
On a Delete button click the numbers from the dropdown get deleted and and on Add Button click numbers are added to the dropdown.
Now if have 1, 2, 3 in my dropdown and if I delete 1, I want the number 2 and 3 to be replaced by 1 and 2. I am not sure how to do this. Can someone please help me?
if(!IsPostBack)
{
List<int> numbers = new List<int>();
Session["data"] = numbers;
rest of other code....
}
protected void btnAddDetail_Click(object sender, EventArgs e)
{
numbers = (List<int>)Session["data"];
if (numbers == null) { numbers = new List<int>(); }
if (numbers.Count!=0)
{
int max = numbers.Max();
numbers.Add(max + 1);
drpdown1.DataSource = numbers;
drpdown1.DataBind();
drpdown1.SelectedValue = numbers.Max().ToString();
Session["data"] = numbers;
}
}
protected void btnDelete(object sender, EventArgs e)
{
numbers = (List<int>)Session["data"];
int detailIndex = numbers.FindIndex(c => c == Convert.ToInt32 (deleteNo));
numbers.RemoveAt(detailIndex);
drpdown1.DataSource = numbers;
drpdown1.DataBind();
Session["data"] = numbers;
}
Now when I rebind the dropdown list I want the numbers 2 and 3 to be replaced by 1 and 2.
If I understand what you are trying to do, try using an index array:
put these two controls in the aspx page:
<asp:DropDownList ID="ddlNumbers" runat="server" />
<asp:Button id="btnRemove" runat="server" />
put this code in your code-behind:
public ArrayList Numbers
{
get
{
return (ArrayList)this.ViewState["Numbers"];
}
set
{
this.ViewState["Numbers"] = value;
}
}
protected override void OnInit(EventArgs e)
{
this.btnRemove.Click += new EventHandler(btnRemove_Click);
base.OnInit(e);
}
void btnRemove_Click(object sender, EventArgs e)
{
this.Numbers.RemoveAt(Convert.ToInt32(this.ddlNumbers.SelectedValue));
this.BindList();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Numbers = new ArrayList();
for (int i = 0; i < 10; i++)
{
this.Numbers.Add(i);
}
this.BindList();
}
}
private void BindList()
{
this.ddlNumbers.Items.Clear();
for (int i = 0; i < this.Numbers.Count; i++)
{
this.ddlNumbers.Items.Add((i + 1).ToString());
}
}
I have 3 check boxes in each row of 8 total rows. I want to have the third checkbox in each row to get checked only when the first two checkboxes are unchecked. I do not want to write a checkRow() method for each row.
What is the best way to go about it?
private void checkRow()
{
for (int i = 0; i < 8; i++)
{
var arraylist = new[] { checkbox1, checkbox2, checkbox3 };
if (checkbox1.Checked || checkbox2.Checked)
{
arraylist[2].Checked = false;
}
else
arraylist[2].Checked = true;
}
}
private void checbox1_CheckedChanged(object sender, EventArgs e)
{
checkRow();
}
private void checbox2_CheckedChanged(object sender, EventArgs e)
{
checkRow();
}
private void checbox3_CheckedChanged(object sender, EventArgs e)
{
checkRow();
}
In response.
private void checkRow()
{
var arraylist = new[] { checkEdit1, checkEdit2, checkEdit3 };
var arraylist1 = new[] { checkEdit4, checkEdit5, checkEdit6 };
var arraylist2 = new[] { checkEdit7, checkEdit8, checkEdit9 };
var array = new[] { arraylist, arraylist1, arraylist2 };
for (int i = 0; i < 8; i++)
{
//if checkedit1 or checkedit2 is checked the checkedit3 should not be checked
if (array[i]....Checked || array[i]....Checked)
{
arraylist[i]...Checked = false;
}
else
arraylist[i]...Checked = true;
}
}
I was trying to do something like this so that I dont have to write the checkRow() for each row
You should use the same method as the handler for all three delegates.
chkbox.CheckedChanged += new EventHandler(chkbox_CheckedChanged);
chkbox2.CheckedChanged += new EventHandler(chkbox_CheckedChanged);
chkbox3.CheckedChanged += new EventHandler(chkbox_CheckedChanged);
private void chkbox_CheckedChanged(object sender, EventArgs e)
{
// do your stuff here
}
Assuming you're not using a DataGridView or other way of organizing them into logical rows, why don't you do the following:
Store the checkboxes in an array so you have easy access to them.
CheckBox[,] checkArray = new CheckBox[8,3]...
Store the row index in the Tag property of the first and second checkboxes.
checkBox01.Tag = 0;
checkBox02.Tag = 0;
checkBox11.Tag = 1;
checkBox12.Tag = 1;
Have all the first and second checkboxes point to the same event handler:
checkBox01.CheckedChanged += new EventHandler(aCheckBox_CheckedChanged);
checkBox02.CheckedChanged += new EventHandler(aCheckBox_CheckedChanged);
checkBox11.CheckedChanged += new EventHandler(aCheckBox_CheckedChanged);
checkBox12.CheckedChanged += new EventHandler(aCheckBox_CheckedChanged);
In the event handler, you now know exactly which check box to update and no longer have to loop:
private void aCheckBox_CheckedChanged(object sender, EventArgs e)
{
int rowIndex = (int)((CheckBox)sender).Tag;
checkArray[rowIndex,2].Checked = !(checkArray[rowIndex,0].Checked ||
checkArray[rowIndex,1].Checked);
}
You can also do this using string lookups with the checkbox name, but it is surely slower and is a pain to refactor later if you choose to rename the checkboxes.