DataList1中怎么实现选择??
DataList1中显示记录,我要选中一条记录后,在下面显示出这条记录的全部详细信息??,
[解决办法]
前台:
<table width= "400 " align= "center ">
<TBODY>
<tr>
<td> <asp:DataList id= "DataList1 " Width= "300 " runat= "server ">
<HeaderTemplate>
<table width= "100% " border= "1 " style= "border-collapse:collapse; " bordercolor= "black " cellpadding= "2 ">
<tr bgcolor= "#ccccff ">
<td> LastName </td>
<td> City </td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr id= 'tr_ <%#DataBinder.Eval(Container.DataItem, "EmployeeID ")%> ' style= "cursor:hand; " onmouseout= "this.bgColor= ' ';this.style.color= ' '; " onmouseover= "this.bgColor= 'aliceblue ' " onclick= "fn_trOnClick(this); ">
<td> <%#DataBinder.Eval(Container.DataItem, "LastName ")%> </td>
<td> <%#DataBinder.Eval(Container.DataItem, "City ")%> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList> </TD> </TR>
<tr>
<td>
<table width= "300 " align= "center " cellpadding= "2 ">
<tr>
<td> LastName: </td>
<td> <input type= "text " id= "iptLastName " > </td>
<td> City: </td>
<td> <input type= "text " id= "iptCity " > </td>
<td> <input type= "reset " value=Reset> </td>
</tr>
</table>
</td>
</tr> </TBODY> </TABLE>
</form>
<script language= "javascript ">
function fn_trOnClick(obj)
{
obj.bgColor = "#dddddd ";
obj.style.color = "red ";
document.all.iptLastName.value = obj.childNodes[0].innerText;
document.all.iptCity.value = obj.childNodes[1].innerText;
}
</script>
后台:
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
string sql = "select top 10 EmployeeID,LastName,City from Employees order by EmployeeID ";
this.DataList1.DataSource = clsDAO.GetData(sql);
this.DataList1.DataBind();
}
}