locked
DropDown selectedValue copy to textbox and AccDataSrc Select query to Label RRS feed

  • Question

  • User1110884122 posted

    greets to all..

    i'm really sorry if i chosed wrong category for my post but a really need some help on my app that i'm developing..

    i'm building an application in VS2008 that works with accessDB where info 'bout ICT equipment in my company is stored.. it's used for printing some official

    papers on charing (obliging) etc. now.. i coded most of the queries and i've created db tables etc... some i presume 'easy to code' things are giving me some trouble..

    <asp:DropDownList ForeColor="Black" ID="ovisni" runat="server" AutoPostBack="true"
    DataSourceID="AccessDataSource2" DataTextField="zaposlenik"
    DataValueField="zaposlenik" BackColor="white" Font-Overline="False">
    </asp:DropDownList>

     this is my code for pulling data from database table zaposlenik (employee) and it fills this dropdown.. now.. i would like to put my selected value to the new textbox when

    the selected value is changed...

    <asp:TextBox ID="submit" Width="60" Text='???????'></asp:TextBox>

     i have a problem with a string that i need to enter to copy this selected value.. i've tried something like <%# ovisni.selectedValue %> but syntax and semantic is somehow wrong i presume.. :)

     i'm not sure do i need some behind code to do that.. do i need same selectedIndexChage or something in <script> tags on the begining... i presume i need that but google brings me nowhere.. :(

     i also have problem with dependent dropdown because i would like to code thing like above but on index change to generate new dropdown from DB.. but as far as i've found out i need AJAX to do that.. :(

    or js.. i please you at least to give me some information on that... what easier to build and about implementation.. because i'm little confused on that metter... google is not helping again! :)

     other problem that gives me headache...:)) there's no end to it :)

     to make a short story shorter.. :) i need to put value from <asp:accessdatasource> selectcommand query which is doing COUNT for rows that are having certain value to the Label..

    what i mean on that is:

     <asp:AccessDataSource ID="AccessDataSource987" runat="server" datafile="database.mdb"
    selectcommand="
    SELECT    COUNT(*) AS Expr1
    FROM      OPREMA
    WHERE     (Vrsta = 1)">
    </asp:AccessDataSource>

    this is my query.. it counts how many of the table entries (equipment) are let's say voip telephones in company.. and resulit is i.e. 123...

    i would like to put that result of the query to the Label.text... i.e.

    <asp:Label ID="labela" Text='?????' runat="server"></asp:Label> ... i've tried also doing it with :

    <asp:DataList ID="DataList1" runat="server" DataSourceID="AccessDataSource987">
    <ItemTemplate>
     Računala: <asp:Label ID="Label1" Text='<%# Eval("Count") %>' runat="server"></asp:Label>
    </ItemTemplate>
    </asp:DataList>

    but i'm also getting nowhere... ignore parameter value of Text because i've tried many many thing...

     <script runat="server">
      private void Page_Load(Object sender, EventArgs e) {
      Label1.Text = AccessDataSource987.SelectCommand; // or selected() ... ...etc. getting nowhere..
    }
    </script>

     sorry if there are english grammar mistakes because it's not my native language.. :) also sorry if i didn't provide enough info about problem..

    any suggestion is welcome and i will be thankful for reply-es... :) i'm using VS2008 .. C# and ajax enabled.. ... :) thank you..

     

     

     

     

     

    Friday, January 16, 2009 3:21 AM

Answers

  • User1580727775 posted

    As you have set the AutoPostBack property of teh DropDown as true, so in the SelectedIndexChanged you can add the code to set the textbox text property,

     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox1.Text = DropDownList1.SelectedItem.Text;
        }

    Now if you Are not using the code behind model then you have to put script tag with runat="server" inside your HTMl add the same code inside that.

     

     

    Plz mark as answer if you get your answer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 16, 2009 4:21 AM
  • User1580727775 posted

    hi,

    Plz check the code,

           DataView view = (DataView)SqlDataSource2.Select(DataSourceSelectArguments.Empty);
            foreach (DataRowView drView in view)
            {
                Label1.Text = drView["Expr1"].ToString();
            }

    In the page_load event add the following code.

    Your sqldatasource html should be,

      <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="Data Source=nusrv-prj;Initial Catalog=PFM_TestDB;Integrated Security=True"
                ProviderName="System.Data.SqlClient" SelectCommand="SELECT COUNT(*) AS Expr1 FROM Users">
            </asp:SqlDataSource>

     

    Plz let me know if the problem still exists.

     

    Plz mark as answer if you have got your answer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 19, 2009 1:29 AM

All replies

  • User1580727775 posted

    As you have set the AutoPostBack property of teh DropDown as true, so in the SelectedIndexChanged you can add the code to set the textbox text property,

     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox1.Text = DropDownList1.SelectedItem.Text;
        }

    Now if you Are not using the code behind model then you have to put script tag with runat="server" inside your HTMl add the same code inside that.

     

     

    Plz mark as answer if you get your answer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 16, 2009 4:21 AM
  • User1110884122 posted

    big thnx.. this thing works... i've had some trouble with context but everything works fine now..

    if you maybe know the answer to other question i'd be thankful.. thnx one more time.. :)

    Friday, January 16, 2009 6:40 AM
  • User1580727775 posted

    hi,

    Plz check the code,

           DataView view = (DataView)SqlDataSource2.Select(DataSourceSelectArguments.Empty);
            foreach (DataRowView drView in view)
            {
                Label1.Text = drView["Expr1"].ToString();
            }

    In the page_load event add the following code.

    Your sqldatasource html should be,

      <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="Data Source=nusrv-prj;Initial Catalog=PFM_TestDB;Integrated Security=True"
                ProviderName="System.Data.SqlClient" SelectCommand="SELECT COUNT(*) AS Expr1 FROM Users">
            </asp:SqlDataSource>

     

    Plz let me know if the problem still exists.

     

    Plz mark as answer if you have got your answer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 19, 2009 1:29 AM
  • User1110884122 posted

     hi .. thank you so mutch.. this is so nice solution with foreach.. it works fantastic..

    problem is solved thnx to you.. you've helped me enough already but i cannot move on without at least one more advice.. :)

    if you can advise me choosing the solution for cascade dropdown.. i have two dropdowns.. they are dependent.. in first there are employees, locations ... etc. when one of the items is selected i would like other dropdown to fill from database with the names/surnames of employees .. if locations are selected to fill it with location names etc..

    i'll try now to do it using ajax,,  so i'll call for help when some problem pops-up.. :) and it will :) thanks once again man .. :)

    enjoy and take care.. switching to dropdown :)

    Monday, January 19, 2009 7:46 AM
  • User1110884122 posted

     

    SORRY duplicate post... i'm currently away from workplace, sick, so i'm online using HSDPA/EDGE cell access.. it works not so fine..

    adm/mod delete this post plz. thnx.

     

    hi .. thank you so mutch.. this is so nice solution with foreach.. it works fantastic..

    problem is solved thnx to you.. you've helped me enough already but i cannot move on without at least one more advice.. :)

    if you can advise me choosing the solution for cascade dropdown.. i have two dropdowns.. they are dependent.. in first there are employees, locations ... etc. when one of the items is selected i would like other dropdown to fill from database with the names/surnames of employees .. if locations are selected to fill it with location names etc..

    i'll try now to do it using ajax,,  so i'll call for help when some problem pops-up.. :) and it will :) thanks once again man .. :)

    enjoy and take care.. switching to dropdown :)

    Monday, January 19, 2009 7:48 AM
  • User1110884122 posted

     i found topic here on forum related to that matter.. sorry for no earlier better checking.. :) back to work.. :)

    Monday, January 19, 2009 7:50 AM
  • User1110884122 posted

     hi .. thank you so mutch.. this is so nice solution with foreach.. it works fantastic..

    problem is solved thnx to you.. you've helped me enough already but i cannot move on without at least one more advice.. :)

    if you can advise me choosing the solution for cascade dropdown.. i have two dropdowns.. they are dependent.. in first there are employees, locations ... etc. when one of the items is selected i would like other dropdown to fill from database with the names/surnames of employees .. if locations are selected to fill it with location names etc..

    i'll try now to do it using ajax,,  so i'll call for help when some problem pops-up.. :) and it will :) thanks once again man .. :)

    enjoy and take care.. switching to dropdown :)

    Monday, January 19, 2009 7:52 AM
  • User1580727775 posted

    Hi laufer666 ,

    Nice to hear that you are solved.

    I am really feeling embarrassed as you have told me thank you for so many times.......... :)...just kidding......thank to you too..............

    regarding your cascading dropdown, it can be implemented with simple asp.net 2.0...no ajax is required...but if you are using that is also fine.........

    Plz check this link for cascaaing dropdown in ajax,

    http://www.asp.net/ajax/ajaxcontroltoolkit/samples/CascadingDropDown/CascadingDropDown.aspx

    Monday, January 19, 2009 11:55 PM
  • User1110884122 posted

     hahaha.. :) LOL... i would neve get to the idea to do it with foreach.. that's why so many thanks.. i should have said well done few more times.. :) how to build cascade dropdown whithout ajax ? with asp.net only.. ? :)

    Tuesday, January 20, 2009 2:13 AM
  • User1580727775 posted

    Hi,

    I have not worked with cascading dropdown in ajax but whatever scenario you told me,

    You have two ddls and when you select one ddl value it should populate the other with the corresponding values.

    Say for example, you have a counter ddl and when you select India  then the state ddl should populate all the stats fro the country india.

    So on selectionChange event of the first ddl you can bind the second(city) dll with the corresponding city values.

    That is what i meant by "with out ajax"..nothing more than that.. :)

     

    Tuesday, January 20, 2009 2:23 AM
  • User1110884122 posted

    hmm.. that was my 'first of all' idea.. but i have not managed to realize it... binding part gave me some headache..

    ajax as itself technology that supports background data exchange would probably work smoother etc. but i don't mind

    page reloads etc. as far as it works.. so solution you suggested is fully ok for me.. i'll try again to code it and let you know.. :)

    no thnx this time :) promise :) LOL.. cya.. 

    Tuesday, January 20, 2009 3:52 AM