473,387 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

problem with button and listbox in edititemtemplate

I have a problem.
When I click in edit datagrid button I show two listbox and two button.
I use two button to move data between two listbox.

My problem is that I can't call the listbox in the button_click function
because the only way to find the listbox is:

(listbox)e.item.findcontrol["listboxId"]

What s the solution to this problem?
thanks
Damiano

My code is:

protected void dg_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem)
{
((ListBox)e.Item.FindControl("lbxTUUpdate")).Items .Clear();
((ListBox)e.Item.FindControl("lbxTU1Update")).Item s.Clear();
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataS ource =
(user.GetFreeTU()).Tables[0];
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataV alueField =
"UserName";
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataB ind();

((ListBox)e.Item.FindControl("lbxTU1Update")).Data Source =
(user.GetGroup(Int16.Parse(e.Item.Cells[0].Text))).Tables[0];
((ListBox)e.Item.FindControl("lbxTU1Update")).Data ValueField =
"UserName";
((ListBox)e.Item.FindControl("lbxTU1Update")).Data Bind();
}
}

and this in edititemtemplate:

<table cellpadding=0 cellspacing=0 border=0 width=100%>
<tr align=center>
<td>
<asp:ListBox id="lbxTUUpdate" runat="server" Width="150px"
Height="150px" />
</td>
<td>
<asp:button Text=">>" commandname="Add" Runat="Server"
ID="btnAddUpdate" BorderWidth="1" BackColor="#ffffff" BorderColor="#000000"
/><br>
<asp:button Text="<<" commandname="Remove" Runat="Server"
ID="btnRemoveUpdate" BorderWidth="1" BackColor="#ffffff"
BorderColor="#000000" />
</td>
<td>
<asp:ListBox id="lbxTU1Update" runat="server" Width="150px"
Height="150px" />
</td>
</tr>
</table>

this is the button function (but don't work)

protected void lbxDisp(Object sender, CommandEventArgs e)
{
if (e.CommandName == "Add")
{
for (int i = 0; i < lbxTUUpdate.Items.Count; i++)
{
if (lbxTUUpdate.Items[i].Selected)
{
lbxTU1Update.Items.Add(lbxTUUpdate.Items[i].Text);
lbxTUUpdate.Items.Remove(lbxTUUpdate.Items[i].Text);
}
}
}
else
{
for (int i = 0; i < lbxTU1Update.Items.Count; i++)
{
if (lbxTU1Update.Items[i].Selected)
{
lbxTUUpdate.Items.Add(lbxTU1Update.Items[i].Text);
lbxTU1Update.Items.Remove(lbxTU1Update.Items[i].Text);
}
}
}
}
Nov 18 '05 #1
1 2243
instead of button_click function, you can handle that in dg_ItemCommand
method.
chech if which button is clicked e.CommandName, and access the list boxes.

hth,
Av.
"yamne" <da***************@libero.it> wrote in message
news:e0**************@TK2MSFTNGP12.phx.gbl...
I have a problem.
When I click in edit datagrid button I show two listbox and two button.
I use two button to move data between two listbox.

My problem is that I can't call the listbox in the button_click function
because the only way to find the listbox is:

(listbox)e.item.findcontrol["listboxId"]

What s the solution to this problem?
thanks
Damiano

My code is:

protected void dg_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem)
{
((ListBox)e.Item.FindControl("lbxTUUpdate")).Items .Clear();
((ListBox)e.Item.FindControl("lbxTU1Update")).Item s.Clear();
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataS ource =
(user.GetFreeTU()).Tables[0];
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataV alueField =
"UserName";
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataB ind();

((ListBox)e.Item.FindControl("lbxTU1Update")).Data Source =
(user.GetGroup(Int16.Parse(e.Item.Cells[0].Text))).Tables[0];
((ListBox)e.Item.FindControl("lbxTU1Update")).Data ValueField =
"UserName";
((ListBox)e.Item.FindControl("lbxTU1Update")).Data Bind();
}
}

and this in edititemtemplate:

<table cellpadding=0 cellspacing=0 border=0 width=100%>
<tr align=center>
<td>
<asp:ListBox id="lbxTUUpdate" runat="server" Width="150px"
Height="150px" />
</td>
<td>
<asp:button Text=">>" commandname="Add" Runat="Server"
ID="btnAddUpdate" BorderWidth="1" BackColor="#ffffff"
BorderColor="#000000"
/><br>
<asp:button Text="<<" commandname="Remove" Runat="Server"
ID="btnRemoveUpdate" BorderWidth="1" BackColor="#ffffff"
BorderColor="#000000" />
</td>
<td>
<asp:ListBox id="lbxTU1Update" runat="server" Width="150px"
Height="150px" />
</td>
</tr>
</table>

this is the button function (but don't work)

protected void lbxDisp(Object sender, CommandEventArgs e)
{
if (e.CommandName == "Add")
{
for (int i = 0; i < lbxTUUpdate.Items.Count; i++)
{
if (lbxTUUpdate.Items[i].Selected)
{
lbxTU1Update.Items.Add(lbxTUUpdate.Items[i].Text);
lbxTUUpdate.Items.Remove(lbxTUUpdate.Items[i].Text);
}
}
}
else
{
for (int i = 0; i < lbxTU1Update.Items.Count; i++)
{
if (lbxTU1Update.Items[i].Selected)
{
lbxTUUpdate.Items.Add(lbxTU1Update.Items[i].Text);
lbxTU1Update.Items.Remove(lbxTU1Update.Items[i].Text);
}
}
}
}

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
8
by: David | last post by:
This is something I had never seen before. On an aspx page, upon pressing a link button for which I have an event handler in the code behind, the screen shows nothing but a line that says "true"...
5
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all...
4
by: Marcos Beccar Varela | GamaCom Argentina | last post by:
Hello Everyone. I need to use a gridview, that when I use the Update command one of the colums, instead of showing a textbox where the user can write, I need a combobox (listobx), where there are...
0
by: Erik | last post by:
Why isn't my update method getting called? Pasted below is an aspx from a 1.1 application I'm working on. It has two textboxes and a button for inserting data into the database, and a datagrid...
5
by: Brad Baker | last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL database. At the top of the page I have the following code: <%@ Page Language="C#" Debug="true" %> <%@ import...
0
by: ashwin | last post by:
I have a Data Grid to display employee names and codes. On clicking a button (outside the datagrid) I perform some calculations which sets the fields of other columns in the datagrid. The problem...
2
by: Danielle | last post by:
All - Thanks in advance for any help you can provide. I've been working with a GridView in Visual Basic for a long time trying to get a list of contacts and to be able to edit and delete the...
0
by: ashwin | last post by:
I have a Data Grid to display employee names and codes. On clicking a button (outside the datagrid) I perform some calculations which sets the fields of other columns in the datagrid. The problem...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.