绑定了一个REPEATER,一个DATALIST,怎么样才能只显示一个啊
我第一次选择时显示了一个REPEATER,第二次选择时出现了DATALIST,那个REPEATER也还在上面,但是我如果只要一个时间显示一个该怎么做呢? <script runat= "server ">
void Page_Load(Object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
OleDbConnection condatabase;
OleDbCommand cmdSelectdatabase;
OleDbDataReader dtrdatabase;
// Retrieve records from database
condatabase = new OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=E:\\powerflow\\loadflow.mdb ");
condatabase.Open();
cmdSelectdatabase = new OleDbCommand( "Select * from main ", condatabase);
dtrdatabase = cmdSelectdatabase.ExecuteReader();
// Bind to dropdownlist
droplist.DataSource = dtrdatabase;
droplist.DataTextField = "TYPE ";
droplist.DataBind();
dtrdatabase.Close();
condatabase.Close();
}
}
void Search_Click(object sender, System.EventArgs e)
{
OleDbConnection condatabase;
string strSelect;
string strsql;
string tt;
OleDbCommand cmdSelect1;
OleDbCommand cmdSelect2;
OleDbDataReader strdatabase;
condatabase = new OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=E:\\powerflow\\loadflow.mdb ");
strSelect = "Select SIGN From main Where TYPE=@type ";
cmdSelect1 = new OleDbCommand(strSelect, condatabase);
cmdSelect1.Parameters.Add( "@type ", droplist.SelectedValue);
tt = droplist.SelectedValue;
strsql = "select * from " + tt;
condatabase.Open();
cmdSelect2 = new OleDbCommand(strsql, condatabase);
strdatabase = cmdSelect2.ExecuteReader();
if ((int)cmdSelect1.ExecuteScalar() != 0)
{
rptdatabase.DataSource = strdatabase;
rptdatabase.DataBind();
}
else
{
node.DataSource = strdatabase;
node.DataBind();
}
strdatabase.Close();
condatabase.Close();
}
</script>
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:DropDownList
ID= "droplist "
Runat= "Server " />
<asp:Button ID= "Button1 "
Text= "查询 "
Runat= "Server " OnClick= "Search_Click "/>
<asp:Repeater ID= "rptdatabase " runat= "server ">
<HeaderTemplate>
<table style= "top:800px " border= "1 " ">
<tr bgcolor= "#eeeeee ">
<th> BUSNAME </th>
<th> PERUNITS </th>
<th> NODE1 </th>
<th> NODE2 </th>
<th> NODETYPE </th>
<th> Umag </th>
<th> Uangle </th>
<th> PL </th>
<th> QL </th>
<th> PG </th>
<th> QG </th>
<th> PERUNIT </th>
<th> U0 </th>
<th> LimitValue1 </th>
<th> LimitValue2 </th>
<th> Pc </th>
<th> Qc </th>
<th> NodeA </th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "BUSNAME ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "PERUNITS ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODE1 ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODE2 ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODETYPE ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "Umag ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "Uangle ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "PL ")%> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "QL ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "PG ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "QG ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "PERUNIT ")%> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "U0 ")%> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "LimitValue1 ")%> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "LimitValue2 ")%> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "Pc ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "Qc ")%> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NodeA ") %> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:DataList
ID= "node "
Runat= "Server " >
<HeaderTemplate>
<table style= " top:140px " border= "1 " cellpadding= "4 " cellspacing= "1 " width= "100% ">
<tr bgcolor= "#eeeeee ">
<th> 编号 </th>
<th> shiduan </th>
<th> moduan </th>
<th> NODE1 </th>
<th> NODE2 </th>
<th> BRANCHTYPE </th>
<th> R </th>
<th> X </th>
<th> B </th>
<th> NODEA </th>
<th> NODEB </th>
<th> NODEC </th>
<th> NODED </th>
<th> NODEE </th>
<th> RADIO </th>
<th> NODEF </th>
<th> NODEG </th>
<th> NODEH </th>
<th> NODEI </th>
<th> NODEJ </th>
<th> NODEK </th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "ID ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "shiduan ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "moduan ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODE1 ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODE2 ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "BRANCHTYPE ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "R ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "X ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "B ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODEA ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODEB ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODEC ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODED ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODEE ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "RADIO ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODEF ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODEG ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODEH ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODEI ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODEJ ") %> </td>
<td height= "10px "> <%# DataBinder.Eval(Container.DataItem, "NODEK ") %> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
[解决办法]
选种一个的时候,让另一个DataSource = null