Category Archives: LinkButton

[RESOLVED] How to write code for download a file..

Hello,

I have web page, in that I place some links(hyperlinks or linkbuttons).

each button, when user clicks then a file should be downloaded to the user system..

files that are to be downloaded exists in asp.net website project folder>>downloads folder..

can any one give code for the above requirement.

Many Thanks,

Gouse Baig.

[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] HTML Encoding in an asp:LinkButton

Hey All

I am trying to use HTML Encoding in an asp:LinkButton, but it is not working for me. Here is my code:

<% foreach (var id in item.DataID)
	 { %>
		<asp:LinkButton runat="server" ID="DailyUnitValueHyperLink"
					Text="Daily Trends"
					onclick="DailyUnitValueHyperLink_Click"
					CommandArgument="<%: id %>"></asp:LinkButton>
   <% } %>


I am getting the DataId from list of string on my page Model. I am then trying to place that ID into the CommandArgument of the LinkButton. But it is not working.

I have tried both of these and neither work:

I don't think a code block like this can work.   You're trying to create multiple LinkButtons, all with the same ID, and ID's are required to be unique.

I suggest using a Repeater to handle this.

http://www.w3schools.com/ASPNET/aspnet_repeater.asp 

[RESOLVED] show a modal popup after insert to database

I am trying to show a modalpopup window after I do an insert to a database.  What they want is a screen to popup with all the problems they just submitted to the db.  the modalpopupexender keeps asking me for a targetcontrolId but I don't need one.  How do I get around this. since the submit button they use to see modalpopup is part of a different panel.

Here is point where I insert to my DB.


  insertUpdateDelete(sql)
        Next


then here is next code
 FillProblemGrid()   'Go get the problems via a private sub below
        txtFind.Text = String.Empty
        ddlSrpEvent.SelectedValue = SrpID
        pnlSRP.Visible = False
        pnlProblems_ModalPopupExtender.Show()   'popup the modal window that allows them to see problems




Private Sub FillProblemGrid()
        Dim UnitId As String = lblHidSrpId.Text
        Dim PersId As String = lblHidSoldierId.Text


        sql = "Select q.strtask, Case WHEN ed.bitAnswer = 1 THEN 'NOGO' Else 'GO' end bitAnswer from tblSRPQuestion as q INNER JOIN tblSRPEventData as ed on ed.intQuestionId = q.intQuestionId Where bitAnswer = 1 " _
            & "and intUnitSrpId = " & UnitId & " intPersonnelId = " & PersId


        myGridProblems.DataSource = getData(sql)
        myGridProblems.DataBind()


 

kldeutsch

the modalpopupexender keeps asking me for a targetcontrolId but I don't need one.  How do I get around this.

You could set the TargetControlID to a dummy button with style="display:none" or a hiddenfield.

I have tried setting it to a hidden linkbutton, but it gives me an error, i will try an html button and see what happens, but it seems it does not like it when i Hide the target control