472,119 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 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 1821

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Dmitry Korolyov [MVP] | last post: by
reply views Thread by Beorn | last post: by
18 posts views Thread by Dave Sauny | last post: by
2 posts views Thread by Phil | last post: by

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.