Category Archives: DropDownList

[RESOLVED] Dropdownlist is empty when web page displays

 A web site project, 4 pages.  First page just has button links to redirect to another page. When button link is cliced,  the data is retrieved from SQL Server through stored procedures and they are in a class file.  Able to call the procedures and pass the information through SET Properties and right before the page is displayed, checked and data is in the dropdownlist control then redirect to show page.  The dropdowlist is empty, should I be using something different to show the page with the data?  Have tryied REDIRECT and then fill dropdownlist and its still empty on displayed.

Thanks for any help.

Show your codes please.

At which page did you get the data? If you want them to be displayed in second page, then you need to do data bind on this page. Or, you can pass the data got in the first page as session passed to the second page. 

UndecidedLatest code:

From 1st Page

Response.Redirect(http://localhost:2467/OIA%20Email%20Maintenance%20Web/EmailRecipient.aspx)

 

On 2nd Page in LOAD:

Me.pasEmailMaintenance.getAutoNoticeKeyInfo(0)                                (from Class file)

Me.ddlAutoNoticeKey = Me.pasEmailMaintenance.AutoNotice             (from Class file)

At this point checked ddl.AutoNoticeKey.Items(0).Value and does have a value.

 

 

 

Please can someone help me with this. 

not sure what this class is Me.pasEmailMaintenance.AutoNotice    and is Me.ddlAutoNoticeKey you dropdownlist name?  

Me.ddlAutoNoticeKey.items.add(new system.web.webcontrols.listitem("display value", "key value")) is the way to add to a drop down

have you tried running debugger and see if your AutoNotice has any type of value?                  

Me.pasEmailMaintenance.AutoNotice is dropdownlist populate from a stored procedure in class file. Using the AutoNotice to populate ddlAutoNoticeKey which is the dropdownlist on the page. Use a class file because retrieve this information will be used on more that one page. I update the ddlAutoNoticeKey in the Page_Load. Right after that I checked by messagebox and using a random index and did get the data, but no data when the page displayed. Now that I changed the code by adding items way Lorddog suggested and now when message box displays it just says OK.

I am newbie to ASP.net.

I finally got it, I had

Me.ddlAutoNoticeKey.DataSource = Me.pasEmailMaintenance.AutoNotice

and what I needed was:

Me.ddlAutoNoticeKey.DataSource = Me.pasEmailMaintenance.AutoNotice.Items

[RESOLVED] autocomplete TextBox with data from a SQL SERVER

Hi all, im new at asp. net and im making a web page with 3 dropdownlist filtering DATA, and then i display a Gridview with the data selected. But i also have some TextBoxs and i want them to autocomplete according to the filters i previously selected. Im working all of this with no code behind.

Thank all, and here the code. I Bold The TextBox so you can see it clearly :D.

<%@ Import Namespace="System.Data" %>
<%@ Page Language="VB" Debug="True" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data.OLEDB" %>
<%@ import Namespace="System.Data.OleDb.OleDbException" %>


<form id="form1" runat="server">


<asp:LinkButton ID="LinkButton5" runat="server" Text="Default"
    PostBackUrl="http://localhost:49724/Default.aspx"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton4" runat="server" Text="Editar/Actualizar/Eliminar Empleado"
    PostBackUrl="http://localhost:49724/EditEmpleado.aspx"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton7" runat="server" Text="Editar/Actualizar/Eliminar Producto"
    PostBackUrl="http://localhost:49724/EditProducto.aspx"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton8" runat="server" Text="Editar/Actualizar/Eliminar Categoria"
    PostBackUrl="http://localhost:49724/EditCategoria.aspx"></asp:LinkButton>


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestingConnectionString %>"


    SelectCommand="SELECT [PROJID] FROM [sxb_Proyectos] ORDER BY [PROJID]">


</asp:SqlDataSource>


<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TestingConnectionString %>"


    SelectCommand="SELECT DISTINCT Ax50_Empleados.rut, Ax50_HorasRegistradas.rut
                    FROM Ax50_Empleados
                    INNER JOIN Ax50_HorasRegistradas
                    ON Ax50_Empleados.rut= Ax50_HorasRegistradas.rut
                    where ([PROJID] = CASE WHEN @PROJID = '-1' THEN [PROJID] ELSE @PROJID END)
                    ORDER BY Ax50_Empleados.rut">


<SelectParameters>


<asp:ControlParameter ControlID="DropDownList1" Name="PROJID" PropertyName="SelectedValue"/>


</SelectParameters>


</asp:SqlDataSource>


<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:TestingConnectionString %>"


    SelectCommand="SELECT DISTINCT sxb_Producto.Producto, Ax50_HorasRegistradas.LINEPROPERTYID
                    FROM sxb_Producto
                    INNER JOIN Ax50_HorasRegistradas
                    ON sxb_Producto.Producto = Ax50_HorasRegistradas.LINEPROPERTYID
                    where (([rut] = CASE WHEN @rut=  '-1' THEN [rut] ELSE @rut END)
                    AND
                    ([PROJID] = CASE WHEN @PROJID = '-1' THEN [PROJID] ELSE @PROJID END))
                    ORDER BY sxb_Producto.Producto">


<SelectParameters>


<asp:ControlParameter ControlID="DropDownList2" Name="rut" PropertyName="SelectedValue"/>
<asp:ControlParameter ControlID="DropDownList1" Name="PROJID" PropertyName="SelectedValue"/>


</SelectParameters>


</asp:SqlDataSource>


<table>
<tr>
<td>Proyecto</td>
<td>


<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"  AppendDataBoundItems="true"
DataTextField="PROJID" DataValueField="PROJID">
<asp:ListItem Value="0"><Select an option></asp:ListItem>
<asp:ListItem Value="-1"><Select All></asp:ListItem>
                    

</asp:DropDownList>
</tr>


<tr>
<td>Rut Empleado</td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" AppendDataBoundItems="true" enableviewstate="false"
DataTextField="rut" DataValueField="rut">
<asp:ListItem Value="-1"><Select All></asp:ListItem>


</asp:Dropdownlist>


</td>
</tr>


<tr>
<td>Producto</td>
<td>
<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" AppendDataBoundItems="true" enableviewstate="false"
DataValueField="Producto" DataTextField="Producto">
<asp:ListItem Value="-1"><Select All></asp:ListItem>


</asp:DropDownList>
</td>
</tr>
</table>
<br />
<hr />
<table><tr><td>Codigo Proyecto</td><td>Nombre Proyecto</td><td>Cliente</td></tr>
<tr><td>
    

</td>
<td>
    <asp:textbox runat="server" ReadOnly="True"></asp:textbox>
</td>
<td>
    <asp:textbox runat="server"></asp:textbox>
</td>


</tr>
</table>
<hr />


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="PROJID"
    DataSourceID="SqlDataSource4"
    EmptyDataText="There are no data records to display."
    onrowectedindexchanged="GridView1_SelectedIndexChanged">
    <Columns>
        <asp:TemplateField>
        <ItemTemplate>
        <asp:LinkButton ID="Editar" Text="Editar" runat="server" CommandName="Edit"></asp:LinkButton>
        </ItemTemplate>
        <EditItemTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" AutoPostBack="True" AppendDataBoundItems="true" enableviewstate="false"
            Text="Actualizar"></asp:LinkButton>
        <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" AutoPostBack="True"
            Text="Cancelar"></asp:LinkButton>
        </EditItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="PROJID" HeaderText="PROJID"
            SortExpression="PROJID" />
        <asp:BoundField DataField="rut" HeaderText="rut"
            SortExpression="rut" />
        <asp:BoundField DataField="LINEPROPERTYID" HeaderText="LINEPROPERTYID"
            SortExpression="LINEPROPERTYID" />
        <asp:BoundField DataField="QTY" HeaderText="QTY" SortExpression="QTY" />
        <asp:BoundField DataField="TXT" HeaderText="TXT" SortExpression="TXT" />
        <asp:BoundField DataField="TRANSDATE" HeaderText="TRANSDATE"
            SortExpression="TRANSDATE" DataFormatString="{0:d}" />
        <asp:BoundField DataField="Comentario" HeaderText="Comentario"
            SortExpression="Comentario" />
    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
    ConnectionString="<%$ ConnectionStrings:TestingConnectionString %>"
    ProviderName="<%$ ConnectionStrings:TestingConnectionString.ProviderName %>"
    SelectCommand="SELECT [PROJID], [rut], [LINEPROPERTYID], [QTY], [TXT], [TRANSDATE], [TRANSSTATUS], [DIMENSION], [DIMENSION3_], [Comentario]
                   FROM [Ax50_HorasRegistradas]
                   WHERE
                   (([rut] = CASE WHEN @rut=  '-1' THEN [rut] ELSE @rut END)
                   AND
                   ([PROJID] = CASE WHEN @PROJID = '-1' THEN [PROJID] ELSE @PROJID END)
                   AND
                   ([LINEPROPERTYID] = CASE WHEN @Producto = '-1' THEN [LINEPROPERTYID] ELSE @Producto END))"


     UpdateCommand="UPDATE [Ax50_HorasRegistradas] set Comentario = @Comentario WHERE PROJID = @PROJID AND TRANSDATE = @TRANSDATE">


<UpdateParameters>
<asp:Parameter Name="PROJID" />
<asp:Parameter Name="TRANSDATE" />
</UpdateParameters>


<SelectParameters>
<asp:ControlParameter ControlID="DropDownList2" Name="rut" PropertyName="SelectedValue"/>
<asp:ControlParameter ControlID="DropDownList1" Name="PROJID" PropertyName="SelectedValue"/>
<asp:ControlParameter ControlID="DropDownList3" Name="Producto" PropertyName="SelectedValue"/>
</SelectParameters>


</asp:SqlDataSource>
</form>


well it didnt bold the text box because i think is pasted codes, so the lines of the textbox are 107 and 110.

thank so much

Hi,


Check below links,


http://www.aspdotnetcodes.com/AutoComplete_From_Database.aspx

http://www.developerbarn.com/net-code-samples/75-using-ajax-auto-complete-extender-database.html



You can use ajax extensions and  web services:

.aspx page:

<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </ajaxToolkit:ToolkitScriptManager>
  <div>
    <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
    <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1"
            ServiceMethod="GetProducts" ServicePath="WebService.asmx" TargetControlID="txtSearch"> </ajaxToolkit:AutoCompleteExtender>
          </div>


WebService.cs:

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;

/// <summary>
/// Summary description for WebService
/// </summary>
[ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{
    public WebService()
    {
        //Uncomment the following line if using designed components
        //InitializeComponent();
    }
    [WebMethod]
    public string[] GetProducts(string prefixText)
    {
       
            string sql = "Select rut from table Where rut like @prefixText";
            SqlDataAdapter da = new SqlDataAdapter(sql, ConfigurationManager.ConnectionStrings["TestingConnectionString"].ToString());
            da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.NVarChar, 50).Value = prefixText + "%";
            DataTable dt = new DataTable();
            da.Fill(dt);
            string[] items = new string[dt.Rows.Count];
            int i = 0;
            foreach (DataRow dr in dt.Rows)
            {
                items.SetValue(dr["rut"].ToString(), i);
                i++;
            }
            return items;

        }


       
    }




 

 

hi, thanks for answering but with ajax it doesnt work, y pasted the code like this. 

<%@ Import Namespace="System.Data" %>
<%@ Page Language="VB" Debug="True" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data.OLEDB" %>
<%@ import Namespace="System.Data.OleDb.OleDbException" %>


<script>


<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </ajaxToolkit:ToolkitScriptManager>
  <div>
    <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
    <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1"
            ServiceMethod="GetProducts" ServicePath="WebService.asmx" TargetControlID="txtSearch"> </ajaxToolkit:AutoCompleteExtender>
          </div>


</script>






<form id="form1" runat="server">


<asp:LinkButton ID="LinkButton5" runat="server" Text="Default"
    PostBackUrl="http://localhost:49724/Default.aspx"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton4" runat="server" Text="Editar/Actualizar/Eliminar Empleado"
    PostBackUrl="http://localhost:49724/EditEmpleado.aspx"></asp:LinkButton>


............


and it give me an error "Etiqueta de servidor 'ajaxToolkit:ToolkitScriptManager' desconocida."

it doesnt recognize the ajaxtoolkit

Did you download and configure the ajax control toolkit with your Visual studio?

if not, you can download from here:

 http://www.asp.net/ajaxlibrary/act.ashx

http://ajaxcontroltoolkit.codeplex.com/releases/view/43475

 

 

 

 

ok i did all the steps of ajax and nothing happens,now i have this.


<%@ Import Namespace="System.Data" %>
<%@ Page Language="VB" Debug="True" %>


<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data.OLEDB" %>
<%@ import Namespace="System.Data.OleDb.OleDbException" %>
<%@ Import Namespace="AjaxControlToolkit" %>


 <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>
  <div>
    <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
    <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1"
            ServiceMethod="GetProducts" ServicePath="WebService.asmx" TargetControlID="txtSearch"> </ajaxToolkit:AutoCompleteExtender>
  </div>




<form id="form1" runat="server">


<asp:LinkButton ID="LinkButton5" runat="server" Text="Default"
    PostBackUrl="http://localhost:49724/Default.aspx"></asp:LinkButton>
<br />
.
.
.
.
.
.


thanks very much for your help :D

Did you add the webservice.cs (with the GetProducts method) file in the app_code folder ?

if you did already, please mark out the line and start debugging and see if that is calling or not.....

i have the webservice in the same folder as the aspx web page, but what is that of getProducts method? it is something that i have to add as a line, its a file?


thank you for your time.

Please see my first reply.....you can see the GetProducts method there....

public string[] GetProducts(string prefixText)
    {......}


 

hi, and thanks for answering.

i have this for the moment in the aspx file.

<%@ Import Namespace="System.Data" %>
<%@ Page Language="VB" Debug="True" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data.OLEDB" %>
<%@ import Namespace="System.Data.OleDb.OleDbException" %>
<%@ Import Namespace="AjaxControlToolkit" %>


<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>
  <div>
    <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
    <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1"
            ServiceMethod="GetProducts" ServicePath="WebService.asmx" TargetControlID="txtSearch"> </ajaxToolkit:AutoCompleteExtender>
  </div>


<form id="form1" runat="server">


<asp:LinkButton ID="LinkButton5" runat="server" Text="Default"
    PostBackUrl="http://localhost:49724/Default.aspx"></asp:LinkButton>
<br />


and this in the .cs file

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;

/// <summary>  
/// Summary description for WebService  
/// </summary>  
[ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{
    public WebService(prefixText)
    {
        //Uncomment the following line if using designed components  
        //InitializeComponent();  
    }
    [WebMethod]
    public string[] GetProducts(string prefixText)
    {

        string sql = "Select rut from table Where rut like @prefixText";
        SqlDataAdapter da = new SqlDataAdapter(sql, ConfigurationManager.ConnectionStrings["TestingConnectionString"].ToString());
        da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.NVarChar, 50).Value = prefixText + "%";
        DataTable dt = new DataTable();
        da.Fill(dt);
        string[] items = new string[dt.Rows.Count];
        int i = 0;
        foreach (DataRow dr in dt.Rows)
        {
            items.SetValue(dr["rut"].ToString(), i);
            i++;
        }
        return items;

    }



}


and it gives me this error when i debug

Mensaje de error del analizador: Etiqueta de servidor 'ajaxToolkit:ToolkitScriptManager' desconocida.

Error de código fuente: 

Línea 7:  <%@ Import Namespace="AjaxControlToolkit" %>
Línea 8:  
Línea 9:  <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>   
Línea 10:   <div>    
Línea 11:     <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox> 

thanks for your answer


hi there, i still have this error and i did all of the ajax tools stuff

Línea 9:
Línea 10:
Línea 11: <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
Línea 12:   <div>
Línea 13:     <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>

this is my code. 


<%@ Import Namespace="AjaxControlToolkit" %>



<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
  <div>    
    <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>    
    <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1"     
            ServiceMethod="GetProducts" ServicePath="WebService.cs" TargetControlID="txtSearch"> </ajaxToolkit:AutoCompleteExtender>    
  </div> 
</ajaxToolkit:ToolkitScriptManager> 
<form id="form1" runat="server">



i change the code to this and i can see the page now, but the text doesnt show anything.

<%@ Import Namespace="AjaxControlToolkit" %>


<form id="form1" runat="server">


<ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
  <div>
    <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
    <AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1"
            ServiceMethod="GetProducts" ServicePath="WebService.cs" TargetControlID="txtSearch"> </AutoCompleteExtender>
  </div>
</ToolkitScriptManager>



Hello,

please read my first post carefully and see there the servicepath="Webservice.asmx"....put the code inside the webservice.cs file! 

great thanks so much!

show data in a textbox automatically when i choose an item in a dropdownlist

hi all, i have a web page, with some filters using dropdownlist, and when i select items from these dropdownlist, a gridview appear showing data from a sql server. The idea is that when i select an item, from the first or second drop down list, in a textbox appear for example the name of the item i choose from the dropdownlist.

Thanks all for your help. Here is the code. I use only VB and not C#.

<%@ Import Namespace="System.Data" %>
<%@ Page Language="VB" Debug="True" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data.OLEDB" %>
<%@ import Namespace="System.Data.OleDb.OleDbException" %>
<%@ import Namespace="System.Web.UI.WebControls.DataControlFieldCollection" %>
<%@ import Namespace="System.Web.UI.HtmlControls.HtmlGenericControl" %>


<script runat="server">
    

    Dim Proyectos As SqlDataSource
    

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    

        Proyectos = New SqlDataSource
        

        Dim sConnString As String
        sConnString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("TestingConnectionString").ConnectionString
        Proyectos.ConnectionString = sConnString
        Proyectos.ID = "Proyectos"
        

        ' Now configure the INSERT statement. We have to declare the Parameters here
        Proyectos.InsertCommand = "INSERT INTO [sxb_Conocimiento] ([Rut],[IdProducto],[IdCategoria],[Experiencia]) VALUES (@Rut, @IdProducto, @IdCategoria, @Experiencia)"
        Proyectos.InsertParameters.Add("Rut", "")
        Proyectos.InsertParameters.Add("IdProducto", "")
        Proyectos.InsertParameters.Add("IdCategoria", "")
        Proyectos.InsertParameters.Add("Experiencia", "")
        

        Me.Controls.Add(Proyectos)
  

    End Sub
    

    ' The following code is triggered when the Insert button is pressed.
    Protected Sub bInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Clear insert Parameters
        Proyectos.InsertParameters.Clear()
        ' Add parameters with values form Text boxes
        Proyectos.InsertParameters.Add("Rut", Rut.Text.ToString)
        Proyectos.InsertParameters.Add("IdProducto", IdProducto.Text.ToString)
        Proyectos.InsertParameters.Add("IdCategoria", IdCategoria.Text.ToString)
        Proyectos.InsertParameters.Add("Experiencia", Experiencia.Text.ToString)
        ' Do the INSERT command
        Proyectos.Insert()
    End Sub


</script>


<form id="form1" runat="server">


<asp:LinkButton ID="LinkButton5" runat="server" Text="Default"
    PostBackUrl="http://localhost:49724/Default.aspx"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton4" runat="server" Text="Editar/Actualizar/Eliminar Empleado"
    PostBackUrl="http://localhost:49724/EditEmpleado.aspx"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton7" runat="server" Text="Editar/Actualizar/Eliminar Producto"
    PostBackUrl="http://localhost:49724/EditProducto.aspx"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton8" runat="server" Text="Editar/Actualizar/Eliminar Categoria"
    PostBackUrl="http://localhost:49724/EditCategoria.aspx"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton9" runat="server" Text="Editar/Actualizar/Eliminar Valores"
    PostBackUrl="http://localhost:49724/EditValores.aspx"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton10" runat="server" Text="Editar/Actualizar/Eliminar Conocimiento"
    PostBackUrl="http://localhost:49724/EditConocimiento.aspx"></asp:LinkButton>


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestingConnectionString %>"
    SelectCommand="SELECT DISTINCT [Rut] FROM [sxb_Conocimiento]
                    ORDER BY [Rut]">
</asp:SqlDataSource>


<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TestingConnectionString %>"
    SelectCommand="SELECT DISTINCT [IdProducto] FROM [sxb_Conocimiento]
                    WHERE ([Rut] = CASE WHEN @Rut = '-1' THEN [Rut] ELSE @Rut END)
                    ORDER BY [IdProducto]">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="Rut" PropertyName="SelectedValue"/>
</SelectParameters>
</asp:SqlDataSource>


<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:TestingConnectionString %>"
    SelectCommand="SELECT DISTINCT [IdCategoria] FROM [sxb_Conocimiento]
                    WHERE
                    (([Rut] = CASE WHEN @Rut = '-1' THEN [Rut] ELSE @Rut END)
                    AND
                    ([IdProducto] = CASE WHEN @IdProducto = '-1' THEN [IdProducto] ELSE @IdProducto END))
                    ORDER BY [IdCategoria]">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="Rut" PropertyName="SelectedValue"/>
<asp:ControlParameter ControlID="DropDownList2" Name="IdProducto" PropertyName="SelectedValue"/>
</SelectParameters>
</asp:SqlDataSource>


<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:TestingConnectionString %>"
    SelectCommand="SELECT DISTINCT [Experiencia] FROM [sxb_Conocimiento]
                    WHERE
                    (([Rut] = CASE WHEN @Rut = '-1' THEN [Rut] ELSE @Rut END)
                    AND
                    ([IdProducto] = CASE WHEN @IdProducto = '-1' THEN [IdProducto] ELSE @IdProducto END)
                    AND
                    ([IdCategoria] = CASE WHEN @IdCategoria = '-1' THEN [IdCategoria] ELSE @IdCategoria END))
                    ORDER BY [Experiencia]">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="Rut" PropertyName="SelectedValue"/>
<asp:ControlParameter ControlID="DropDownList1" Name="IdProducto" PropertyName="SelectedValue"/>
<asp:ControlParameter ControlID="DropDownList1" Name="IdCategoria" PropertyName="SelectedValue"/>
</SelectParameters>
</asp:SqlDataSource>


<table>
<tr>
<td>Rut</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
        DataSourceID="SqlDataSource1"  AppendDataBoundItems="true" enableviewstate="false"
DataTextField="Rut" DataValueField="Rut" DataTextFormatString="{0}">
<asp:ListItem Value="0"><Select an option></asp:ListItem>
<asp:ListItem Value="-1"><Select All></asp:ListItem>
</asp:DropDownList>
</tr>


<tr>
<td>Producto</td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" AppendDataBoundItems="true" enableviewstate="false"
DataTextField="IdProducto" DataValueField="IdProducto">
<asp:ListItem Value="-1"><Select All></asp:ListItem>
</asp:Dropdownlist>
</td>
</tr>


<tr>
<td>Categoria</td>
<td>
<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" AppendDataBoundItems="true" enableviewstate="false"
DataTextField="IdCategoria" DataValueField="IdCategoria">
<asp:ListItem Value="-1"><Select All></asp:ListItem>
</asp:Dropdownlist>
</td>
</tr>


<tr>
<td>Experiencia</td>
<td>
<asp:DropDownList ID="DropDownList4" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource4" AppendDataBoundItems="true" enableviewstate="false"
DataTextField="Experiencia" DataValueField="Experiencia">
<asp:ListItem Value="-1"><Select All></asp:ListItem>
</asp:Dropdownlist>
</td>
</tr>
</table>


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoPostBack="True" DataKeyNames="Rut" enableviewstate="false" AppendDataBoundItems="true"
    DataSourceID="SqlDataSource5"
    EmptyDataText="There are no data records to display.">
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:LinkButton ID="Editar" Text="Editar" runat="server" CommandName="Edit"></asp:LinkButton>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" AutoPostBack="True" AppendDataBoundItems="true" enableviewstate="false"
        Text="Actualizar"></asp:LinkButton>
    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" AutoPostBack="True"
        Text="Cancelar"></asp:LinkButton>
    </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:LinkButton ID="Apagar" Text="Eliminar" runat="server" CommandName="Delete" OnClientClick='return confirm("Esta seguro que quiere borrar este registro?");' AutoPostBack="True" enableviewstate="false" CausesValidation="false"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="Rut" HeaderText="Rut" SortExpression="Rut" />
    <asp:BoundField DataField="IdProducto" HeaderText="IdProducto" SortExpression="IdProducto" />
    <asp:BoundField DataField="IdCategoria" HeaderText="IdCategoria"
        SortExpression="IdCategoria" />
    <asp:BoundField DataField="Experiencia" HeaderText="Experiencia"
        SortExpression="Experiencia" />
    <asp:BoundField DataField="Resultado" HeaderText="Resultado"
        SortExpression="Resultado" />
    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource5" runat="server"
    ConnectionString="<%$ ConnectionStrings:TestingConnectionString %>"
    ProviderName="<%$ ConnectionStrings:TestingConnectionString.ProviderName %>"
    SelectCommand="SELECT DISTINCT [Rut], [IdProducto], [IdCategoria], [Experiencia], [Resultado] FROM [sxb_Conocimiento]
                   WHERE
                   (([Rut] = CASE WHEN @Rut= '-1' THEN [Rut] ELSE @Rut END)
                   AND
                   ([IdProducto] = CASE WHEN @IdProducto = '-1' THEN [IdProducto] ELSE @IdProducto END)
                   AND
                   ([IdCategoria] = CASE WHEN @IdCategoria = '-1' THEN [IdCategoria] ELSE @IdCategoria END)
                   AND
                   ([Experiencia] = CASE WHEN @Experiencia = '-1' THEN [Experiencia] ELSE @Experiencia END))"


    UpdateCommand="UPDATE [sxb_Conocimiento] set IdProducto = @IdProducto, IdCategoria = @IdCategoria, Experiencia = @Experiencia where Rut = @Rut"


    InsertCommand="INSERT INTO [sxb_Conocimiento] (Rut, IdProducto, IdCategoria, Experiencia) VALUES (@Rut, @IdProducto, @IdCategoria, @Experiencia)"


    DeleteCommand="DELETE from [sxb_Conocimiento] where Rut = @Rut">


    <UpdateParameters>
    <asp:Parameter Name="Rut" />
    </UpdateParameters>


    <DeleteParameters>
    <asp:Parameter Name="Rut"/>
    </DeleteParameters>


    <SelectParameters>
    <asp:ControlParameter ControlID="DropDownList1" Name="Rut" PropertyName="SelectedValue"/>
    <asp:ControlParameter ControlID="DropDownList2" Name="IdProducto" PropertyName="SelectedValue"/>
    <asp:ControlParameter ControlID="DropDownList3" Name="IdCategoria" PropertyName="SelectedValue"/>
    <asp:ControlParameter ControlID="DropDownList4" Name="Experiencia" PropertyName="SelectedValue"/>
    </SelectParameters>


</asp:SqlDataSource>
<br />
<br />
<table>
<tr>
<td>Ingrese Rut</td>
<td>
<asp:TextBox ID="Rut" runat="server"></asp:TextBox>
</tr>
<td>Ingrese IdProducto</td>
<td>
<asp:TextBox ID="IdProducto" runat="server"></asp:TextBox>
</tr>
<td>Ingrese IdCategoria</td>
<td>
<asp:TextBox ID="IdCategoria" runat="server"></asp:TextBox>
</tr>
<td>Ingrese Experiencia</td>
<td>
<asp:TextBox ID="Experiencia" runat="server"></asp:TextBox>
</tr>
</table>


<asp:LinkButton ID="bInsert" runat="server" CausesValidation="True" CommandName="Insert" AutoPostBack="True" AppendDataBoundItems="true" enableviewstate="false" onclick="bInsert_Click"
    Text="Ingresar"></asp:LinkButton>


</form>



if you want to set a textbox's text property according to the selection change of dropdownlist then you can use 

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
         DataSourceID="SqlDataSource1"  AppendDataBoundItems="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" enableviewstate="false"
 DataTextField="Rut" DataValueField="Rut" DataTextFormatString="{0}">
 <asp:ListItem Value="0"><Select an option></asp:ListItem>
 <asp:ListItem Value="-1"><Select All></asp:ListItem>
 </asp:DropDownList>


 Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)


                TextBox1.Text = DropDownList1.SelectedItem.Name
or
                TextBox1.Text = DropDownList1.SelectedValue
            

    End Sub




hi, thanks so much for answering, i changed my code to this :D


<%@ Import Namespace="System.Data" %>
<%@ Page Language="VB" Debug="True" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data.OLEDB" %>
<%@ import Namespace="System.Data.OleDb.OleDbException" %>
<%@ Import Namespace="AjaxControlToolkit" %>
<script runat="server">
 

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
  

        TextBox.Text = DropDownList1.SelectedItem.Name
              

    End Sub
</script>


<form id="form1" runat="server">


<asp:LinkButton ID="LinkButton5" runat="server" Text="Default"
    PostBackUrl="http://localhost:49724/Default.aspx"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton4" runat="server" Text="Editar/Actualizar/Eliminar Empleado"
    PostBackUrl="http://localhost:49724/EditEmpleado.aspx"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton7" runat="server" Text="Editar/Actualizar/Eliminar Producto"
    PostBackUrl="http://localhost:49724/EditProducto.aspx"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton8" runat="server" Text="Editar/Actualizar/Eliminar Categoria"
    PostBackUrl="http://localhost:49724/EditCategoria.aspx"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton9" runat="server" Text="Editar/Actualizar/Eliminar Valores"
    PostBackUrl="http://localhost:49724/EditValores.aspx"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton10" runat="server" Text="Editar/Actualizar/Eliminar Conocimiento"
    PostBackUrl="http://localhost:49724/EditConocimiento.aspx"></asp:LinkButton>


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestingConnectionString %>"
    SelectCommand="SELECT [PROJID] FROM [sxb_Proyectos] ORDER BY [PROJID]">
</asp:SqlDataSource>


<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TestingConnectionString %>"
    SelectCommand="SELECT DISTINCT Ax50_Empleados.rut, Ax50_HorasRegistradas.rut
                    FROM Ax50_Empleados
                    INNER JOIN Ax50_HorasRegistradas
                    ON Ax50_Empleados.rut= Ax50_HorasRegistradas.rut
                    where ([PROJID] = CASE WHEN @PROJID = '-1' THEN [PROJID] ELSE @PROJID END)
                    ORDER BY Ax50_Empleados.rut">


<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="PROJID" PropertyName="SelectedValue"/>
</SelectParameters>
</asp:SqlDataSource>


<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:TestingConnectionString %>"
    SelectCommand="SELECT DISTINCT sxb_Producto.Producto, Ax50_HorasRegistradas.LINEPROPERTYID
                    FROM sxb_Producto
                    INNER JOIN Ax50_HorasRegistradas
                    ON sxb_Producto.Producto = Ax50_HorasRegistradas.LINEPROPERTYID
                    where (([rut] = CASE WHEN @rut=  '-1' THEN [rut] ELSE @rut END)
                    AND
                    ([PROJID] = CASE WHEN @PROJID = '-1' THEN [PROJID] ELSE @PROJID END))
                    ORDER BY sxb_Producto.Producto">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList2" Name="rut" PropertyName="SelectedValue"/>
<asp:ControlParameter ControlID="DropDownList1" Name="PROJID" PropertyName="SelectedValue"/>
</SelectParameters>
</asp:SqlDataSource>


<table>
<tr>
<td>Proyecto</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"  AppendDataBoundItems="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
DataTextField="PROJID" DataValueField="PROJID">
<asp:ListItem Value="0"><Select an option></asp:ListItem>
<asp:ListItem Value="-1"><Select All></asp:ListItem>
</asp:DropDownList>
</tr>


<tr>

this is the text box and the error

 

<td>
    <asp:textbox ID="textbox" runat="server" ReadOnly="True"></asp:textbox>
</td>

Mensaje de error del compilador: BC30456: 'Name' no es un miembro de 'System.Web.UI.WebControls.ListItem'.

Error de código fuente:

Línea 10: Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)  
Línea 11:   
Línea 12:         TextBox.Text = DropDownList1.SelectedItem.Name
Línea 13:               
Línea 14:     End Sub

Please use

DropDownList1.SelectedItem.Text

instead of

DropDownList1.SelectedItem.Name

Sorry for the misinformation

REAL NICE, thanks for your help, but now, how can i show in that Textbox, not the item that i selected, but an item that is in the same table where i get the data to fill the dropdownlist. All the data is in a LOCAL SQL SERVER. In me table i have serveral columns and with the first dropdownlist as you can see i select one. But in the textbox i want to show other column.

the table has

PROJID RUT LINEPROPERTYID QTY TXT TRANSDATE TRANSTATUS columns. The first dropdown select the PROJID columns and in the textbox i would like to show for example the LINEPROPERTYID data according for what i selected in the dropdownlist. 

thank you so much :D

[RESOLVED] listbox with optgroup

is there way to do listbox with optgroup?
i tried just making a header row with different styles but it is still selectable. enabled for that row makes it invisible.
i dont know of a way to use just a plain <select with runat=server and populate the items from code behind.

I did find someones dll that has this ability in their user control but i get a security trust fail when trying to run it. I cannot figure out how to tell the web.config that the dll is safe to run.

 

Doug 

http://weblogs.asp.net/jeff/archive/2006/12/27/dropdownlist-with-optgroup.aspx

 

Check Comment of -  Ben Sloan

The answer is not to use attributes as you suggest, but instead to set the "value" of the listitem which is to be the group header. Set it to something very unlikely to be used again like "$$GROUPHEADER$$GROUPHEADER$$"

Your test against the attribute (to see whether it is null) then becomes: "If item.Value = "$$GROUPHEADER$$GROUPHEADER$$" Then"

Next is to make it a bit easier for the programmer to add groups without having to remember this value string. To do this, I created a class called "OptionGroup" (I'm sure you can work out the contents of it) and then added a public sub on the control you wrote:

       Public Sub AddOptionGroup(ByVal og As OptionGroup)

           Dim optGrpTitle As New ListItem(og.GroupName, "$$GROUPHEADER$$GROUPHEADER$$")

           Me.Items.Add(optGrpTitle)

           For Each li As ListItem In og.Items

               Me.Items.Add(New ListItem(li.Text, li.Value))

           Next

       End Sub

To then add groups in an .aspx page:

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

       If Not IsPostBack Then

           Dim G1Items As New ListItemCollection

           G1Items.Add(New ListItem("G1V1", "G1V1"))

           G1Items.Add(New ListItem("G1V2", "G1V2"))

           G1Items.Add(New ListItem("G1V3", "G1V3"))

           Dim G2Items As New ListItemCollection

           G2Items.Add(New ListItem("G2V1", "G2V1"))

           G2Items.Add(New ListItem("G2V2", "G2V2"))

           G2Items.Add(New ListItem("G2V3", "G2V3"))

           Dim og1 As New OptionGroup("Group1", G1Items)

           Dim og2 As New OptionGroup("Group2", G2Items)

           Me.ddlTest.AddOptionGroup(og1)

           Me.ddlTest.AddOptionGroup(og2)

       End If

   End Sub

Except for that the code remains the same, and works perfectly across postbacks.

This is because the value property of the items does persist in viewstate, I suppose.

thx for that suggestion. I finally found out my problems with adding in someones dll. I had to change the app pool to run under NetworkService :) 

If you want to work w/ optgroup -- you need to use CustomValidator for Validation

Request.Form to get that value on server end

And throw JS from codebehind to update that control

Something along this line

<select name="opt1" id="opt1" >
        <option selected="selected" value="1">Select One</option>
        <optgroup label="aaaa">
        <option value="2">z1</option>
        <option value="3">z2</option>
        <option value="4">Z3</option></optgroup>
        <optgroup label="bbbb">
        <option value="5">X1</option>
        <option value="6">X2</option>
        </optgroup>
       
    </select>


//To get value at server end
int y1  = Int32.Parse(Request.Form["opt1"].ToString());


//To update that control from codebehind
ScriptManager.RegisterStartupScript(this, this.GetType(), "starScript", "Updateopt('" + x1 + "');", true);

[RESOLVED] jsp validation

i have a page called rateuser.aspx. i would like to set a validation such that user A cannot give feedback & rating to himself. how do i do that? because user A can choose the users from a dropdownlist. so how do i validate such that when user A press themselves, an error would pop and say "you cannot choose yourself."

If you know who the user is when you populate the dropdownlist, why not keep "himself" from being on that list. 

how do i do that?

yoghurtculture

how do i do that?

That depends upon how you are populating the dropdown in the first place.  Could you please post all your related markup and code?

(It makes things a lot more readable if you use the Insert Code tool. If you need instructions, see my How to use the Forums' "Insert Code" tool. post.)