how can i detect wich arrow user as clicked in code behind becausee e see the demo and it doesnt show how it works
so i want to load to a left listbox all items from specific sql datasource and then the rigth lisbox just have the one that the user move to rigth listbox so i waant to associate items but they are loaded from diferent sources
27 Answers, 1 is accepted

Try the following JS and code snippet to identify which arrow(transfer from or transfer all from) is clicked.
aspx:
<
telerik:RadListBox
ID
=
"RadListBox1"
runat
=
"server"
AllowTransfer
=
"true"
AutoPostBackOnTransfer
=
"true"
TransferToID
=
"RadListBoxDestination"
OnTransferring
=
"RadListBox1_Transferring"
OnClientTransferring
=
"clientTransfering"
>
<
Items
>
<
telerik:RadListBoxItem
Text
=
"001"
/>
.............................
</
Items
>
</
telerik:RadListBox
>
<
telerik:RadListBox
runat
=
"server"
ID
=
"RadListBoxDestination"
>
</
telerik:RadListBox
>
<script type=
"text/javascript"
>
function
clientTransfering(sender, args)
{
var
target = args.get_domEvent().target.parentNode;
while
(target.nodeName !=
"A"
)
target = target.parentNode;
sender.trackChanges();
if
(target.className.indexOf(
"rlbTransferFrom"
) > -1)
sender.get_items().getItem(0).get_attributes().setAttribute(
"clickedButton"
,
"transferFrom"
);
else
if
(target.className.indexOf(
"rlbTransferAllFrom"
) > -1)
sender.get_items().getItem(0).get_attributes().setAttribute(
"clickedButton"
,
"transferAllFrom"
);
sender.commitChanges();
}
</script>
protected
void
RadListBox1_Transferring(
object
sender, Telerik.Web.UI.RadListBoxTransferringEventArgs e)
{
String transferButton = (sender
as
RadListBox).Items[0].Attributes[
"clickedButton"
].ToString();
}
Thanks
Princy

- all to left
-all to rigth
-one to left
-one to rigth
also i need to pick the icons from a specific folder and read wich icon to asociate with the item from database so icon a is with item a but this values are fom database
also this is not catching the 4 events in codebehind i need to catch them to make diffenrtent actions and write chenges to my db so this in code behind.
String transferButton = (sender
as
RadListBox).Items[0].Attributes[
"clickedButton"
].ToString();
just gets the clicked button and i need if its all to rigth do some action if all to left do other.....

also i have this code to try to populate the listboxes but they wont populate i'm returning a datatable in sql command:
protected void ActualizarListas()
{
int id_atleta = (int)RadGrid1.SelectedValues["id"];
RadListBox1.DataTextField = "Nome";
RadListBox1.DataValueField = "id";
RadListBox1.DataSource = BLL.Patrocinadores.ListarTodosPatrocinadoresNaoAssociados(id_atleta);
RadListBox2.DataTextField = "Nome";
RadListBox2.DataValueField = "id";
RadListBox2.DataSource = BLL.Patrocinadores.ListarTodosPatrocinadoresAssociados(id_atleta);
}
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
ActualizarListas();
}
so iconA match listbox itemA etc
public static DataTable ListarTodosPatrocinadoresAssociados(int id_atleta)
{
ArrayList _arraySqlParams = new ArrayList();
_arraySqlParams.Add(new SqlParameter("id_atleta", id_atleta));
return (SQLHelper.ExecuteDataTable("SELECT TOP (100) PERCENT dbo.Patrocinador.nome, dbo.Patrocinador.id, dbo.Fotos.url_img FROM dbo.Patrocinador INNER JOIN dbo.Fotos ON dbo.Patrocinador.id_foto = dbo.Fotos.id WHERE(dbo.Patrocinador.id IN (SELECT id_patrocinador FROM dbo.Atleta_Patrocinador WHERE (id_atleta = @id_atleta))) ORDER BY dbo.Patrocinador.nome", (SqlParameter[])_arraySqlParams.ToArray(typeof(SqlParameter))));
}

code updated but not working dont see nothing on radlistbox
RadListBox1.DataTextField = "Nome";
RadListBox1.DataValueField = "id";
RadListBox1.DataSource = BLL.Patrocinadores.ListarTodosPatrocinadoresNaoAssociados(id_atleta);
RadListBox1.DataBind();
RadListBox2.DataTextField = "Nome";
RadListBox2.DataValueField = "id";
RadListBox2.DataSource = BLL.Patrocinadores.ListarTodosPatrocinadoresAssociados(id_atleta);
RadListBox2.DataBind();
If you are trying to bind RadListBox from the code behind please review this documentation article where this functionality is explained.
As for your other question would you please elaborate what exactly do you mean by -"also i need to pick the icons from a specific folder and read wich icon to asociate with the item from database so icon a is with item a but this values are fom database" because it is not quite clear, so we could be more helpful.
All the best,
Nencho
the Telerik team

so it read on db img1, then pick on folder img1 to show in this radlistbox
also need to know how i can work with the 4 option in codebehind i havent understood very well
what I need is to access the trsnsfer buttons individually to run a sql command to transfer between listboxes
if you can provide and example I would appreciate that

I can suggest you to use the OnItemDataBound event handler, in order to access the DataItem and assign the ImageUrl to the RadListBoxItem in the following manner :
protected
void
SourceListBox_ItemDataBound(
object
sender, RadListBoxItemEventArgs e)
{
e.Item.ImageUrl = (e.Item.DataItem
as
DataRowView)[
"ImagePathInFolder"
].ToString();
}
As for you second question, you could use the OnTransferred event handler and easily determine which button was clicked, regarding the count of the transferred items (e.Items.Count) and the SourceListBox(e.SourceListBox).
Regards,
Nencho
the Telerik team

hope you understood better, a user previously post at the begin of this post a JS detected mode but how can i related that in codebehind?

public
static
DataTable ListarTodosPatrocinadoresNaoAssociados(
int
id_atleta) // listbox1
{
ArrayList _arraySqlParams =
new
ArrayList();
_arraySqlParams.Add(
new
SqlParameter(
"id_atleta"
, id_atleta));
DataTable r=(SQLHelper.ExecuteDataTable(
"SELECT TOP (100) PERCENT dbo.Patrocinador.nome, dbo.Patrocinador.id, dbo.Fotos.url_img FROM dbo.Patrocinador INNER JOIN dbo.Fotos ON dbo.Patrocinador.id_foto = dbo.Fotos.id WHERE(dbo.Patrocinador.id NOT IN (SELECT id_patrocinador FROM dbo.Atleta_Patrocinador WHERE (id_atleta = @id_atleta))) ORDER BY dbo.Patrocinador.nome"
, (SqlParameter[])_arraySqlParams.ToArray(
typeof
(SqlParameter))));
return
r;
}
public
static
DataTable ListarTodosPatrocinadoresAssociados(
int
id_atleta) listbox2
{
ArrayList _arraySqlParams =
new
ArrayList();
_arraySqlParams.Add(
new
SqlParameter(
"id_atleta"
, id_atleta));
DataTable r= (SQLHelper.ExecuteDataTable(
"SELECT TOP (100) PERCENT dbo.Patrocinador.nome, dbo.Patrocinador.id, dbo.Fotos.url_img FROM dbo.Patrocinador INNER JOIN dbo.Fotos ON dbo.Patrocinador.id_foto = dbo.Fotos.id WHERE(dbo.Patrocinador.id IN (SELECT id_patrocinador FROM dbo.Atleta_Patrocinador WHERE (id_atleta = @id_atleta))) ORDER BY dbo.Patrocinador.nome"
, (SqlParameter[])_arraySqlParams.ToArray(
typeof
(SqlParameter))));
return
r;
}
public
static
int
Remover1PatrocinadorAoAtleta(
int
id_atleta,
string
id_patrocinador) // remove one
{
ArrayList _arraySqlParams =
new
ArrayList();
_arraySqlParams.Add(
new
SqlParameter(
"id_atleta"
, id_atleta));
_arraySqlParams.Add(
new
SqlParameter(
"id_patrocinador"
, id_patrocinador));
return
(SQLHelper.ExecuteNonQuery(
"delete from atleta_patrocinador where id_patrocinador=@id_patrocinador and id_atleta=@id_atleta"
, (SqlParameter[])_arraySqlParams.ToArray(
typeof
(SqlParameter))));
}
public
static
int
RemoverTodosOsPatrocinadoresAoAtleta(
int
id_atleta,
string
id_patrocinador) / remove all - transfer all
{
ArrayList _arraySqlParams =
new
ArrayList();
_arraySqlParams.Add(
new
SqlParameter(
"id_atleta"
, id_atleta));
_arraySqlParams.Add(
new
SqlParameter(
"id_patrocinador"
, id_patrocinador));
return
(SQLHelper.ExecuteNonQuery(
"delete from atleta_patrocinador where id_atleta=@id_atleta"
, (SqlParameter[])_arraySqlParams.ToArray(
typeof
(SqlParameter))));
}
public
static
int
Adicionar1PatrocinadorAoAtleta(
int
id_atleta,
string
id_patrocinador)
{
ArrayList _arraySqlParams =
new
ArrayList();
_arraySqlParams.Add(
new
SqlParameter(
"id_atleta"
, id_atleta));
_arraySqlParams.Add(
new
SqlParameter(
"id_patrocinador"
, id_patrocinador));
return
(SQLHelper.ExecuteNonQuery(
"insert into atleta_patrocinador(id_atleta, id_patrocinador) values (@id_atleta, @id_patrocinador)"
, (SqlParameter[])_arraySqlParams.ToArray(
typeof
(SqlParameter))));
}
i need to bind the 2 listbox with icons and the values and then remove one or all / or add all add one depending on what user clicks
SO here are my sql commands: - hope you have understood why i need to know wich arrow user clicks
so codebehind would be similar to this but in c#, i just need to pick on the corrects arrows and i'm not getting how to pick the arrow clicked event
Private
Sub
add_btn_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
add_btn.Click
BR.Actores.Adicionar1ActorAoFilme(id_filme, lbx_todos_os_actores.SelectedValue)
ActualizarListas()
End
Sub
Private
Sub
add_all_btn_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
add_all_btn.Click
BR.Actores.AdicionarTodososActoresAoFilme(id_filme)
ActualizarListas()
End
Sub
Private
Sub
remove_btn_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
remove_btn.Click
BR.Actores.Remover1ActorAoFilme(id_filme, lbx_actores_deste_filme.SelectedValue)
ActualizarListas()
End
Sub
Private
Sub
remove_all_btn_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
remove_all_btn.Click
BR.Actores.RemoverTodososActoresAoFilme(id_filme)
ActualizarListas()
End
Sub
Private
Sub
btn_ok_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
btn_ok.Click
Me
.Close()
End
Sub
Sub
ActualizarListas()
lbx_todos_os_actores.DisplayMember =
"Nome"
lbx_todos_os_actores.ValueMember =
"Id_Actor"
lbx_todos_os_actores.DataSource = BR.Actores.MostrarTodosOsActores(id_filme)
lbx_actores_deste_filme.DisplayMember =
"Nome"
lbx_actores_deste_filme.ValueMember =
"Id_Actor"
lbx_actores_deste_filme.DataSource = BR.Actores.MostrarActoresAssociadosAoFilme(id_filme)
End
Sub
I have prepared a sample project for you, demonstrating how to determine which arrow was just clicked. Please find the sample attached.
Note that all dll files are removed.
Regards,
Nencho
the Telerik team

I'm always getting items count==0
how can I load an icon near to the listbox I see this:
//DirectoryInfo img24Dir = new DirectoryInfo(Server.MapPath("~/uploads/images/miniaturas/"));
//foreach (FileInfo file in img24Dir.GetFiles("*.png"))
//{
// RadListBoxItem item = new RadListBoxItem(file.Name.Replace(".png", ""));
// item.ImageUrl = "~/uploads/images/miniaturas/" + file.Name;
// RadListBox1.Items.Add(item);
//}
however I'm binding datasource of listbox from database and I need to read a field
in
database ex:
if
it reads imgA loads icon imgAIcon

I have performed some tests locally, but I was unable to replicate the faced issue with the items' count, when the transfer operation is performed. Here is a video, demonstrating the behavior at my end. In addition, I am sending you the sample I have tested with. Could you specify if I had missed something?
Kind regards,
Nencho
the Telerik team

e.SourceListBox.SelectedValue && e.SourceListBox.ClientID == "RadListBox1" but I cant compare them obviously so how I get the selectedvalue of the selected item on a specific listbox?
see image:
http://postimg.org/image/x53xmbljj/
Could you specify how your project differs from the previously provided sample, which behavior was demonstrated in the video?
Regards,
Nencho
the Telerik team

so you go to the gird seltect there a item then it shows associated articles and all articles not associated and when you transfer them it should update db
I am afraid that the provided code snippet is not runnable and I was unable to replicate the faced issue. Therefor, I would like to ask you to provide us with a runnable sample, demonstrating the issue you had faced, in order to inspect it locally.
Kind regards,
Nencho
the Telerik team

the radbox's are connect to the database so when we click on the arrows it must run the commends i showed also in the videobu it doesnt detect some items in radbox
Would you specify why you are calling the ActualizarListas method, each time the Page_Load event is hit? As I can see, the method handles the population with data of both RadListBoxes and it is invoked each time a transfer operation is performed.
All the best,
Nencho
the Telerik team

as you can see in the video sometimes count is zero.
so actualizarlistas just reads from database and populate the correct listbox
for example this method
BLL.Patrocinadores.Adicionar1PatrocinadorAoAtleta(id_atleta,id_patrocinador) is to associate a sponsor with the person selected in the gid but I need to pass id_patrocionador wich is the seletec item in the listbox wich I cant get because count it always zero. I have 4 methods depending on the action taken and other two to read from db
hope you have understood better now...
The problem is caused by the fact that you are rebinding the ListBoxes on each postback too late in the page lifecycle, effectively clearing the selection in each one. And since the transfer operation relies on the selection, it fails.
Try moving the rebinding logic in Page_Init.
Kind regards,
Bozhidar
the Telerik team

int id_atleta = (int)RadGrid1.SelectedValues["id"
]; it breaks because the grid isn't created yet, I think so it gives the error reference is not an object...
also how to get the radlistbox selecteditem/value working with this:
else if (e.Items.Count > 1 && e.SourceListBox.ClientID == "RadListBox2")
The else if (e.Items.Count > 1 && e.SourceListBox.ClientID == "RadListBox2") statement fails, because the ClientID of the ListBox is actually not RadListBox2. This can be seen in you own video at 1:09 minutes, when you hover the ListBox. I've attached a screenshot, where you can see the actual ID of the ListBox.
As for the first issue, you can use a hidden field and set the Grid Selected value on the client, and in the Page_Init event use this hidden field to retrieve it.
Regards,
Bozhidar
the Telerik team

remember that the user as to select an item in the grid for the listboxes getting updated so I cant pass it on page_init because I don't know what user selects at that moment
could you provide a code to fix this?
As I said in my previous reply, you can set the hidden field value on the client, when you know the Grid Selection, and then get it's value in pageInit. You can also use the following article as a reference:
http://forums.asp.net/t/1627237.aspx
Regards,
Bozhidar
Telerik
