469,140 Members | 1,205 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,140 developers. It's quick & easy.

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 1752

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
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.