This is a migrated thread and some comments may be shown as answers.

Listbox

15 Answers 194 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Rakesh
Top achievements
Rank 1
Rakesh asked on 28 Oct 2011, 12:21 AM
How can we find the items of the Radlistbox while traversing through the list of items using javascript....

Note:I got 5 controls for each item ,I have to find the instance of each control while traversing through the list...

could you please help me in finding the solution....

15 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 28 Oct 2011, 07:37 AM
Hello Rakesh,

You can try the following javascript.

ASPX:

<telerik:RadListBox ID="RadListBox1" runat="server" OnClientItemDoubleClicked="OnClientItemDoubleClicked">
<Items>
   <telerik:RadListBoxItem Text="A" Value="1" />
</Items>
 <ItemTemplate>
   <telerik:RadTextBox ID="RadTextBox1" runat="server" Text="Test1"></telerik:RadTextBox>
   <telerik:RadTextBox ID="RadTxt1" runat="server" Text="Test"></telerik:RadTextBox>
 </ItemTemplate>
</telerik:RadListBox>


JS:
<script type="text/javascript">
function OnClientItemDoubleClicked(sender, args)
{
   var items = sender.get_items();
  for (var i = 0; i < items.get_count(); i++)
 {
   var itm= items.getItem(i).findControl("RadTxt1");
   alert(itm.get_value());
 }
}
</script>

Thanks,
Princy.
0
Rakesh
Top achievements
Rank 1
answered on 28 Oct 2011, 02:30 PM
Thank You for your reply

my requirement is bit different I would like to write cientsideevent for one of the textboxes wichich are part of my itemtemplate in radlistbox...within that event i want to find controls of and calculate the total.....

I got five controls with 4 labels and 2 textboxes for each item in radlistbox and i want to write onvaluechanged client side event for one of the textboxes..as soon as it losses it focus i want to find the remaining controls and calculate the total and put that in second textbox..

so i got around 5 to 10 items for each radlistbox

whenever i to go through these items in each radlistbox i want to find the controls and calculate the total...

awaiting for your reply

thanks in advance
0
Rakesh
Top achievements
Rank 1
answered on 28 Oct 2011, 03:34 PM
Hey can you help in finding the label control of a radlistbox within the for loop and also how to get the value of the label control after finding it....


Thank you
0
Rakesh
Top achievements
Rank 1
answered on 28 Oct 2011, 04:19 PM
Can you also help me finding the control which is present in footer template of radlistbox..

I have label present in the footer template of radlistbox I need to find the instance of it

Can you help me in finding it...
0
Princy
Top achievements
Rank 1
answered on 31 Oct 2011, 07:35 AM
Hello Rakesh,

You can try the following code snippet to find the Label inside RadListBox and the FooterTemplate controls.

ASPX:
<telerik:RadListBox ID="RadListBox2" runat="server" Skin="Vista" AutoPostBack="true">
   <ItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "Text") %>'></asp:Label>
   </ItemTemplate>
   <FooterTemplate>
    <asp:Label ID="Label11" runat="server" Text="Label11"></asp:Label>
   </FooterTemplate>
   <Items>
     <telerik:RadListBoxItem Text="RadMenu" />
     <telerik:RadListBoxItem Text="RadComboBox" />
     <telerik:RadListBoxItem Text="RadListBox" Selected="true" />
  </Items>
</telerik:RadListBox>
<asp:Button ID="btn" runat="server" Text="click" OnClick="btn_Click" />

C#:
protected void Page_Load(object sender, EventArgs e)
{
   for (int i = 0; i < RadListBox2.Items.Count; i++)
  {
    RadListBox2.Items[i].DataBind();
  
}
protected void btn_Click(object sender, EventArgs e)
{
  for (int i = 0; i < RadListBox2.Items.Count; i++)
   {
    Label lbl = (Label)RadListBox2.Items[i].FindControl("Label1");
    string val = lbl.Text;
   }
   Label footerlbl= (Label)RadListBox2.Footer.FindControl("Label11");
   footerlbl.Text = "changed";
}

Thanks,
Princy.
0
Rakesh
Top achievements
Rank 1
answered on 31 Oct 2011, 04:25 PM
thank You very much....

Can you do me a favour.i have  textbox control which calculates total amount i want to get value of that textbox in codebehind ...

I am calculating the total amount in the client side that the reason why it's value is not rendering to server

Is htere any way that i can get the value of the textbox and any other control values in the code behind...
0
Princy
Top achievements
Rank 1
answered on 02 Nov 2011, 08:28 AM
Hello Rakesh,

To get the value in server side you can store the value of Textbox in a HiddenField and access the HiddenField from code behind. Here is the code.

JS:
<script type="text/javascript">
 function OnClientClick()
 {
   var RadTextBox2 = $find('<%=RadTextBox2.ClientID%>');
   RadTextBox2.set_textBoxValue("abc");
   document.getElementById("Hidden").value = RadTextBox2.get_textBoxValue();
 }
</script>

C#:
protected void btn_Click(object sender, EventArgs e)
{
 RadTextBox3.Text = Hidden.Value;
}

Thanks,
Princy.
0
Rakesh
Top achievements
Rank 1
answered on 02 Nov 2011, 09:10 PM
hi princy

thank you for your reply

I have small question how can we find label or a textbox control of a radlistbox using javascript.
label and textbox or not rad controls they are just normal asp controls.

One more question is how can i set radtextbox or radlabel control visbility to true using javascript intially it is false and want to set back to true in javascript function.

0
Princy
Top achievements
Rank 1
answered on 03 Nov 2011, 08:08 AM
Hello Rakesh,

Here is the sample code to access the Label control in a button click.
<asp:Button ID="btn" runat="server" Text="click" OnClick="btn_Click" OnClientClick="accessTextBox();" />
<script type="text/javascript">
 function Show()
    {
        var txtBox = $find('<%=RadTxtBox1.ClientID %>');
        listBox.get_items().getItem(1).get_element("Label1")
    }
</script>
NB: Referring the same ListBox

You can try the following approach to achieve your second requirement.
<telerik:RadTextBox ID="RadTxtBox1"  ClientEvents-OnLoad="OnClientLoad"  runat="server">
</telerik:RadTextBox>
<input type="button" value="Show" onclick="Show();" />
<asp:Button ID="btn" runat="server" Text="click" OnClick="btn_Click" OnClientClick="accessTextBox();" />
 
<script type="text/javascript">
 function OnClientLoad(sender)
    {
    sender.set_visible(false);
    }
    function Show()
    {
        var txtBox = $find('<%=RadTxtBox1.ClientID %>');
        txtBox.set_visible(true);
    }
</script>

Thanks,
Princy.
0
Rakesh
Top achievements
Rank 1
answered on 03 Nov 2011, 03:05 PM
thank you...


As label is part of my listbox how can I set it's visibility
 when i am trying to find it it is returning HTMLLIElement that is true
but how can i set it's visibilty

I tried

elementobject.style.display='inherit'
*elementobject is instance of my lable control in listbox
but it is not working
0
Rakesh
Top achievements
Rank 1
answered on 03 Nov 2011, 10:28 PM
I have a probel in finding the index of the each item of the radlistbox

I have 7 items in radlistbox... each item consists of 5 controls and i have a textbox control in it so i wrote onvaluechanged client side event for it so i am able to find the index of the first item but when i hit tab on textbox of the first item focus is moved to textbox of the next item but my itemindex is still 0 it should be one actually...

but when click on second item and try to see item index it is 1 now...

but what i need is whenever i hit tab on firstitem the item index should be 1.

i dont want to go through the loop........


can you help me please...

thank you...
0
Princy
Top achievements
Rank 1
answered on 04 Nov 2011, 06:03 AM
Hello Rakesh,

To set the visibility of Label you can try the following javascript.

JS:
<script type="text/javascript">
 function Show()
 {
  var listBox = $find('<%=lstbx.ClientID%>');
  var label= listBox.get_items().getItem(0).get_element("Label1")
  label.style.visibility = "Hidden";
 }
</script>

For the second question I am not quite sure about the requirement and the way you are attaching the event. Please elaborate/give code.

Thanks,
Princy.
0
Rakesh
Top achievements
Rank 1
answered on 04 Nov 2011, 02:18 PM

thank you....

function

 

 

looseChanged_AmountBox(sender, args) {

 

 

 

var statusID = '<%=StatusLabel.ClientID %>';

 

 

 

var status = document.getElementById(statusID);

 

 

 

//var status = '<%=Session["status"] %>';

 

 

 

//var statusHiddenFeild = document.getElementById('<%=statusHiddenFeild.ClientID %>');

 

 

 

var list = $find('<%=looseChangeListBox.ClientID %>');

 

 

 

var subTotalAmountTextBox = $find('<%=((RadTextBox)looseChangeListBox.Footer.FindControl("subtotalLabelTextBox")).ClientID %>');

 

 

 

var itemIndex = list.get_items().indexOf(list.get_selectedItem());

 

 

alert(itemIndex);

 

 

if (status.innerText == "O") {

 

 

 

var Count = list.get_items().getItem(itemIndex).findControl("amountBox");

 

alert(Count.get_value());

 

 

var countOffSet = list.get_items().getItem(itemIndex).findControl("countOffSetLabel");

 

alert(countOffSet.get_value());

 

 

var offSetValue = (parseFloat(Count.get_value()) - parseFloat(countOffSet.get_value()));

 

alert(offSetValue);

countOffSet.set_value(

 

'(' + parseFloat(offSetValue) + ')');

 

A = OpenBank(list, status, subTotalAmountTextBox, itemIndex);

countOffSet.set_visible(

 

true);

 

 

 

//list.get_items().getItem(itemIndex).findControl("countOffSetLabel").set_visible(true);

 

}

 

 


else
{

 

A = CloseBank(list, status, subTotalAmountTextBox);

}

 

getTotalSum();

}

I have a radlistbox with 7 items in it each item consists of these control
label,Radnumerictextbox(amountBox),label,label,radnumerictextbox and radnumeric textbox(countOffSetLabel) in sequence ,so for countOffSetLabel i wrote onload event inorder set visbility false intially ,and i wrote onvaluechanged for amountBox,so this gets fired when ever i entered value in amountbox and hit tab,after hitting the tab I am making countoffsetlabel visbility true,and focus is set to next item amountbox this is good but when I am trying to find index of the item it is coming of with 0 actually it is should be 1,if i select physically with mouse i am getting it as 1 but i dont want user to do that so whenever user hit tab and moved to second item i want that item index....

Thank you.....

0
Anuja
Top achievements
Rank 1
answered on 09 May 2014, 10:33 AM
Hi , 

I need to bind paragraph in  to list box with separator between two  list items. I have attached the image for your reference. Please have a look and provide me solution.

Thanks and Regards,
Anuja.J
0
Shinu
Top achievements
Rank 1
answered on 09 May 2014, 12:03 PM
Hi Anuja,

Please try the following code snippet to achieve your scenario.

ASPX:
<telerik:RadListBox ID="RadListBox1" runat="server" DataSourceID="SqlDataSource1"
    DataTextField="Data" DataValueField="Id" OnItemDataBound="RadListBox1_ItemDataBound">
</telerik:RadListBox>

CSS:
<style type="text/css">
    .listSeparator
    {
        background-color: Black !important;
    }
</style>

C#:
protected void RadListBox1_ItemDataBound(object sender, RadListBoxItemEventArgs e)
{
    if (e.Item.Index > 0)
    {
        RadListBoxItem sepItem = new RadListBoxItem();
        sepItem.Enabled = false;
        sepItem.CssClass = "listSeparator";
        sepItem.Attributes.Add("isSeparator", "True");
        RadListBox1.Items.Insert(e.Item.Index, sepItem);
    }
}

Thanks,
Shinu.
Tags
ListBox
Asked by
Rakesh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Rakesh
Top achievements
Rank 1
Anuja
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Share this question
or