473,388 Members | 1,385 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,388 software developers and data experts.

Bind listbox inside Bound datalist

In the code below, I have an editItemTemplate that will have to have a
long list of ip's bound to it. The problem is that the lisbox is not
seen by asp.net until after the datalist containing it is exposed.

Is there a way to bind the ddl inside of an already databound
templated column?

Thanks , of course

Michael

void Page_Load ( Object src, EventArgs e ) {
if ( !IsPostBack ) {
// fetch and store data into Session
string query = "Select * from desktops";
Session [ "myTable" ] = ( fetchData ( query, "portchart" )
).Tables [ 0 ];
bindList ( );
}
}
void myListEditHandler ( Object src, DataListCommandEventArgs e
) {
myList.EditItemIndex = e.Item.ItemIndex;
bindList ( );
// clear optional message
msg.Text = "";
}

void myListCancelHandler ( Object src, DataListCommandEventArgs
e ) {
myList.EditItemIndex = -1;
bindList ( );
}

void myListUpdateHandler ( Object src, DataListCommandEventArgs
e ) {
// e.Item represents the current row in edit mode ...
// get updated row values
string ip = ( ( TextBox ) e.Item.FindControl ( "ip" ) ).Text;
string node = ( ( TextBox ) e.Item.FindControl ( "node" )
).Text;
string location = ( ( TextBox ) e.Item.FindControl (
"location" ) ).Text;
string term = ( ( TextBox ) e.Item.FindControl ( "term_id" )
).Text;
string mon = ( ( TextBox ) e.Item.FindControl ( "MON_TAG" )
).Text;

// load data from Session
DataTable myTable = ( DataTable ) Session [ "myTable" ];

// get and update row
DataRow myRow = myTable.Rows [ e.Item.ItemIndex ];
myRow [ "ip_addr" ] = ip;
myRow [ "node" ] = node;
myRow [ "location" ] = location;
myRow [ "term_id" ] = term;
myRow [ "MON_TAG" ] = mon;
myTable.AcceptChanges ( );

// refresh data in Session
Session [ "myTable" ] = myTable;

// set edit mode off
myList.EditItemIndex = -1;
bindList ( );

// optional message
msg.Text = "Data for <b>" +
( ( Label ) e.Item.FindControl ( "nodelbl" ) ).Text +
"</b> updated";
}

void bindList ( ) {
// bind list to current data in Session
myList.DataSource = Session [ "myTable" ];
string query = "Select ip_addr from ips where in_use =0";
myList.DataBind ();

}
</script>
</head>

<body>

<div class="header"><h3>PortChart</h3></div>

<hr size=1 width=90%>

<div align="center">
<form runat="server">
<%--asp:listbox id="lstFAQs" runat="server" Rows="1"
DataTextField="ip_addr" DataValueField="ip_addr" /--%>

<p><asp:label id="msg" runat="server" /></p>

<asp:datalist id="myList" runat="server"
width="75%"
cellpadding=5
repeatcolumns=1
backcolor="ghostwhite"
onEditCommand="myListEditHandler"
onUpdateCommand="myListUpdateHandler"
onCancelCommand="myListCancelHandler">

<headertemplate>
Port Chart
</headertemplate>

<headerstyle backcolor="darkslategray"
forecolor="khaki" font-bold />

<itemtemplate>
<asp:linkbutton runat="server" commandname="edit"
text='<%# ( ( DataRowView ) Container.DataItem ) [ "node"
] %>' />
</itemtemplate>

<itemstyle font-size="8pt" verticalalign="top" />

<edititemtemplate>

<table cellspacing=1 cellpadding=1 class="editor" width=100%
align="center">
<tr>
<th colspan=2><asp:label id="nodelbl" runat="server"
text='<%# ( ( DataRowView ) Container.DataItem ) [
"node" ] %>' /></th>
</tr>
<tr>
<td>Ip Address </td>
<td>
<asp:listbox id="lstFAQs" runat="server" Rows="1"
DataTextField="ip_addr" DataValueField="ip_addr" />
</td>
</tr>
<tr>
<td>Node Name </td>
<td><asp:textbox id="node" runat="server"
text='<%# ( ( DataRowView ) Container.DataItem ) [
"node" ] %>' /></td>
</tr>
<tr>
<td>User Name: </td>
<td><asp:textbox id="location" runat="server"
text='<%# ( ( DataRowView ) Container.DataItem ) [
"location" ] %>' /></td>
</tr>
<tr>
<td>Terminal Id: </td>
<td><asp:textbox id="term_id" runat="server"
text='<%# ( ( DataRowView ) Container.DataItem ) [
"term_id" ] %>' /></td>
</tr>
<tr>
<td>Monitor Tag: </td>
<td><asp:textbox id="MON_TAG" runat="server"
text='<%# ( ( DataRowView ) Container.DataItem ) [
"MON_TAG" ] %>' /></td>
</tr>
<tr>
<td>Cpu Tag: </td>
<td><asp:textbox id="CPU_TAG" runat="server"
text='<%# ( ( DataRowView ) Container.DataItem ) [
"CPU_TAG" ] %>' /></td>
</tr>
<tr>
<td>Comments: </td>
<td><asp:textbox id="COMMENTS" runat="server" rows=5
textmode="multiline"
text='<%# ( ( DataRowView ) Container.DataItem ) [
"COMMENTS" ] %>' /></td>
</tr>
<tr align="center">
<td colspan=2>
<asp:linkbutton commandname="update" runat="server"
text="Update" />
<asp:linkbutton commandname="cancel" runat="server"
text="Cancel" />
</td>
</tr>
</table>

</edititemtemplate>

</asp:datalist>

</form>
</div>
<hr size=1 width=90%>
</body>
</html>
Nov 18 '05 #1
0 1898

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

Similar topics

4
by: Moojjoo | last post by:
Ok fellow C# developers: How do creat an instance of an object inside a dataset or datagrid. Example I need to have a placeholder inside a dataset. Any help would be great.
3
by: Dmitry Korolyov [MVP] | last post by:
Is that possible? In other words, I want a dropdown list (and other list-type controls) which appears in edit more of a templated column to be populated with data at the run time. An attempt to do so...
0
by: Beorn | last post by:
Does anybody have experience using a bound ListBox within a DataList? The DataList should repeat for a list of Categories, each category holds a list of components under that category. The User...
1
by: Bigtoga | last post by:
Okay - I'm going crazy here trying to figure out how to do this - here goes: I have a DataList populated by a DataReader. In the DataReader, a column is present called "IsInCategory". I want to...
0
by: Steve | last post by:
Hi, I have a problem here with bounding data inside a datalist. Currently I am working on a page which I can have a list of items using a datalist(listA). Inside this datalist(listA) i would...
18
by: Dave Sauny | last post by:
Ok, its a friday, I'm at work and I cant get this to work: I have 3 listboxes on one tab control page. when i select an item in listbox1 i want whatever is selected on the other 2 listboxes...
1
by: Mike | last post by:
I have a Datalist control on my page that I have binded to a table of available categories. In the Item Template I have a CheckboxList control bound to the products available in each Category. I...
2
by: Phil | last post by:
I have a datalist (DataList1)... with an itemtemplate... then a table - server side (Table1)... then another datalist (DataList2)... another itemtemplate... another table - server side (Table2)...
2
by: ASP Developer | last post by:
Is it possible to bind a datalist that is inside of a bound datalist? Any help would be greatly appreciated.
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.