Ciao.
Sto provando a realizzare delle select dinamiche in ASP.Net con le DropDownList.
Ho però due problemi che non riesco a risolvere:
1) Rendere invisibile il GridView1 quando si seleziona un valore dalla DropDownList1 e visualizzare solo il GridView2;
2) Svuotare le DropDownList2 e DropDownList3 quando cambio la selezione nella DropDownList1.
Sapete aiutarmi per favore?
Grazie
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>
<%@ Import Namespace="System.Configuration" %>
<script runat="server">
public void Page_Load (Object sender, EventArgs e)
{
OdbcConnection myConnectionString = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
myConnectionString.Open();
myConnectionString.Close();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write("Aggiornato!");
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnMySQL %>"
ProviderName="<%$ ConnectionStrings:ConnMySQL.ProviderName %>"
SelectCommand="SELECT nome, email FROM tbl_login WHERE 1 AND EMAIL IS NOT NULL ORDER BY ID DESC LIMIT 0, 15 "
DataSourceMode="DataSet"
ConflictDetection="CompareAllValues"
EnableCaching="true"
CacheKeyDependency="Mykey"
CacheDuration="Infinite">
</asp:SqlDataSource>
<asp:sqldatasource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnMySQL %>"
ProviderName="<%$ ConnectionStrings:ConnMySQL.ProviderName %>"
SelectCommand="SELECT nome, email FROM tbl_login WHERE 1 AND EMAIL=? "
DataSourceMode="DataSet"
ConflictDetection="CompareAllValues"
EnableCaching="true"
CacheKeyDependency="Mykey"
CacheDuration="Infinite">
<selectparameters>
<asp:controlparameter Name="email" ControlID="DropDownList1" PropertyName="SelectedValue" Direction="Input" />
</selectparameters>
</asp:sqldatasource>
<asp:sqldatasource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnMySQL %>"
ProviderName="<%$ ConnectionStrings:ConnMySQL.ProviderName %>"
SelectCommand="SELECT nome, email, ip_address FROM tbl_login WHERE 1 AND EMAIL=? AND NOME=?"
DataSourceMode="DataSet"
ConflictDetection="CompareAllValues"
EnableCaching="true"
CacheKeyDependency="Mykey"
CacheDuration="Infinite">
<selectparameters>
<asp:controlparameter Name="email" ControlID="DropDownList1" PropertyName="SelectedValue" Direction="Input" />
<asp:controlparameter Name="nome" ControlID="DropDownList2" PropertyName="SelectedValue" Direction="Input" />
</selectparameters>
</asp:sqldatasource>
<br /><br />
<asp:DropDownList ID="DropDownList1" runat="server" Visible="true"
AppendDataBoundItems="true"
DataSourceID="SqlDataSource1"
AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
DataTextField="email"
DataValueField="email">
<asp:ListItem>Seleziona un valore</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" Visible="true"
AppendDataBoundItems="true"
DataSourceID="SqlDataSource2"
AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
DataTextField="Nome"
DataValueField="Nome">
<asp:ListItem Value="">---</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server" Visible="true"
AppendDataBoundItems="true"
DataSourceID="SqlDataSource3"
AutoPostBack="True"
DataTextField="IP_ADDRESS"
DataValueField="IP_ADDRESS">
<asp:ListItem Value="">---</asp:ListItem>
</asp:DropDownList>
<br /><br />
<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSource1"
AllowPaging="True"
AllowSorting="True"></asp:GridView>
<br /><br />
<asp:GridView ID="GridView2" runat="server"
DataSourceID="SqlDataSource2"
AllowPaging="True"
AllowSorting="True">
</asp:GridView>
</form>
</body>
</html>