Salve a tutti,
premetto che sono un pivello di ASP.NET e che per fare quelle 4 righe di codice sono impazzito per questi forum
il mio problema è molto semplice, mi piacerebbe poter aprire una connessione al DB tramite una ListItem
come?
in una pagina ho creato la mia form con tanto di pulsante e DropDownList con i suoi ListItem poi ho seguito un po dai forum per recuperare il dato (che poi è il nome della tabella) e passarlo in un altra pagina dove mi crea il DataGrid .... ecco sapete tutti che ho bisogno di una string (command) su cui memorizzare la select
il problema e che se non riesco a prendere il valore del ListItem non posso fare la select dinamica...
cosa mi dite?
1° WEBFORM
2° WEBFORMcodice:<%@ Page Language="C#" %> <HTML> <HEAD> <title>Autenticazione</title> <script runat="server"> protected static string sCmdArea = ""; void Page_Load(object sender, EventArgs e) { this.ViewState.Add("Area1", "stringa"); sCmdArea = (string)ViewState["Area1"]; Welcome.Text = "Hello, " + Context.User.Identity.Name; } void Signout_Click(object sender, EventArgs e) { FormsAuthentication.SignOut(); Response.Redirect("Login.aspx"); } void Button1_Click(object sender, EventArgs e) { sCmdArea = (string)ViewState["Area1"]; Server.Transfer("Webform1.aspx"); } </script> </HEAD> <body> <h3> Using Forms Authentication</h3> <asp:Label ID="Welcome" runat="server" /> <form id="Form1" runat="server"> <asp:Button ID="Submit1" OnClick="Signout_Click" Text="Sign Out" runat="server" /> <asp:Button id="Button1" runat="server" Text="Button" OnClick="Button1_Click"></asp:Button> <asp:DropDownList id="DropDownList1" runat="server"> <asp:ListItem>CR</asp:ListItem> <asp:ListItem>DB</asp:ListItem> </asp:DropDownList> </p> </form> </body> </HTML>
HELP MEcodice:namespace Web3Progect { /// <summary> /// Summary description for WebForm1. /// </summary> public class WebForm1 : System.Web.UI.Page { public _default sourcepage; protected System.Web.UI.WebControls.DataGrid DataGrid1; private void Page_Load(object sender, System.EventArgs e) { string ConnectionString = Convert.ToString("Data Source=CDPTS1;User Id=IVRDEVELOPER;Password=IVRDEVELOPER;Integrated Security=no"); _default sourcepage = (Web3Progect._default)Context.Handler; string CommandText = sourcepage.Property1; OracleConnection myConnection = new OracleConnection(ConnectionString); OracleCommand myCommand = new OracleCommand(CommandText, myConnection); OracleDataAdapter myDataAdapter= new OracleDataAdapter(); myDataAdapter.SelectCommand = myCommand; DataSet myDataSet = new DataSet(); try { myConnection.Open(); myDataAdapter.Fill(myDataSet); DataGrid1.DataSource = myDataSet; DataGrid1.DataBind(); } catch (Exception ex) { throw (ex); } finally { myConnection.Close(); } } . . . . . . .![]()

Rispondi quotando