In the code below, I have an editItemTemplat e 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 myListEditHandl er ( Object src, DataListCommand EventArgs e
) {
myList.EditItem Index = e.Item.ItemInde x;
bindList ( );
// clear optional message
msg.Text = "";
}
void myListCancelHan dler ( Object src, DataListCommand EventArgs
e ) {
myList.EditItem Index = -1;
bindList ( );
}
void myListUpdateHan dler ( Object src, DataListCommand EventArgs
e ) {
// e.Item represents the current row in edit mode ...
// get updated row values
string ip = ( ( TextBox ) e.Item.FindCont rol ( "ip" ) ).Text;
string node = ( ( TextBox ) e.Item.FindCont rol ( "node" )
).Text;
string location = ( ( TextBox ) e.Item.FindCont rol (
"location" ) ).Text;
string term = ( ( TextBox ) e.Item.FindCont rol ( "term_id" )
).Text;
string mon = ( ( TextBox ) e.Item.FindCont rol ( "MON_TAG" )
).Text;
// load data from Session
DataTable myTable = ( DataTable ) Session [ "myTable" ];
// get and update row
DataRow myRow = myTable.Rows [ e.Item.ItemInde x ];
myRow [ "ip_addr" ] = ip;
myRow [ "node" ] = node;
myRow [ "location" ] = location;
myRow [ "term_id" ] = term;
myRow [ "MON_TAG" ] = mon;
myTable.AcceptC hanges ( );
// refresh data in Session
Session [ "myTable" ] = myTable;
// set edit mode off
myList.EditItem Index = -1;
bindList ( );
// optional message
msg.Text = "Data for <b>" +
( ( Label ) e.Item.FindCont rol ( "nodelbl" ) ).Text +
"</b> updated";
}
void bindList ( ) {
// bind list to current data in Session
myList.DataSour ce = 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="ghos twhite"
onEditCommand=" myListEditHandl er"
onUpdateCommand ="myListUpdateH andler"
onCancelCommand ="myListCancelH andler">
<headertemplate >
Port Chart
</headertemplate>
<headerstyle backcolor="dark slategray"
forecolor="khak i" font-bold />
<itemtemplate >
<asp:linkbutt on runat="server" commandname="ed it"
text='<%# ( ( DataRowView ) Container.DataI tem ) [ "node"
] %>' />
</itemtemplate>
<itemstyle font-size="8pt" verticalalign=" top" />
<edititemtempla te>
<table cellspacing=1 cellpadding=1 class="editor" width=100%
align="center">
<tr>
<th colspan=2><asp: label id="nodelbl" runat="server"
text='<%# ( ( DataRowView ) Container.DataI tem ) [
"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:textbo x id="node" runat="server"
text='<%# ( ( DataRowView ) Container.DataI tem ) [
"node" ] %>' /></td>
</tr>
<tr>
<td>User Name: </td>
<td><asp:textbo x id="location" runat="server"
text='<%# ( ( DataRowView ) Container.DataI tem ) [
"location" ] %>' /></td>
</tr>
<tr>
<td>Terminal Id: </td>
<td><asp:textbo x id="term_id" runat="server"
text='<%# ( ( DataRowView ) Container.DataI tem ) [
"term_id" ] %>' /></td>
</tr>
<tr>
<td>Monitor Tag: </td>
<td><asp:textbo x id="MON_TAG" runat="server"
text='<%# ( ( DataRowView ) Container.DataI tem ) [
"MON_TAG" ] %>' /></td>
</tr>
<tr>
<td>Cpu Tag: </td>
<td><asp:textbo x id="CPU_TAG" runat="server"
text='<%# ( ( DataRowView ) Container.DataI tem ) [
"CPU_TAG" ] %>' /></td>
</tr>
<tr>
<td>Comments: </td>
<td><asp:textbo x id="COMMENTS" runat="server" rows=5
textmode="multi line"
text='<%# ( ( DataRowView ) Container.DataI tem ) [
"COMMENTS" ] %>' /></td>
</tr>
<tr align="center">
<td colspan=2>
<asp:linkbutt on commandname="up date" runat="server"
text="Update" />
<asp:linkbutt on commandname="ca ncel" runat="server"
text="Cancel" />
</td>
</tr>
</table>
</edititemtemplat e>
</asp:datalist>
</form>
</div>
<hr size=1 width=90%>
</body>
</html>