Array data to datagrid..

Last post 03-11-2009 12:13 PM by hajan. 2 replies.

Sort Posts:

  • Array data to datagrid..

    03-11-2009, 11:11 AM

    hi firends,

    I have thousands of numbers..
    I wanna get the highest 10 numbers in dec order.. And store it in array in the same order..
    And wanna bind that data to the datagrid..

    Its correspoding data also want to add in datagrid..

    What should i do?

    Please give some idea..

    Or any articles related to it..

    Thanks..

     

     

  • Re: Array data to datagrid..

    03-11-2009, 12:00 PM
    Answer
    • Member
      37 point Member
    • alexey.popikov
    • Member since 03-10-2009, 12:05 PM
    • Russia
    • Posts 10

     Hi :)

    Here step-by-step instruction.

    1. Create SQL request like select top(10) * from [Table] order by [YourDescColumn] desc

    2. Use SqlCommand to get data from database.

    3. Add datagrid control on your asp.net page and bind with data from second step.

     

    Hope that can help you :)

  • Re: Array data to datagrid..

    03-11-2009, 12:13 PM
    • Contributor
      3,138 point Contributor
    • hajan
    • Member since 06-04-2008, 1:30 PM
    • Macedonia
    • Posts 552

    Hi there,

    Do you keep your data in Database, XML file, or ???

    If you keep them in Database, than you can #1 retrieve the highest 10 by using the following query:
     

    select top(10) numbers from DatabaseTable order by numbers desc

     
    Than, why not just using the GridView control from VS.NET ? Add this Control:
     
    DO THE FOLLOWING IN YOUR ASPX  PAGE

    <asp:GridView ID="GridView1" runat="server" DataSourceID="sqlDataSource1">
    </asp:GridView>
     

    than add SqlDataSource:
     

    <asp:SqlDataSource ID="sqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:yourConnectionString %>"
    SelectCommand="select top(10) numbers from DatabaseTable order by id desc"></asp:SqlDataSource>
    At the end just replace your Connection string (String which will connect your application to the Database).
    You can store your connection string in the Web.config file (if you don't have Web.config, create in your Web application Project)
    And in the web config, add the following code (replace your strings appropriately)
     
    <connectionStrings>
    <add name="yourConnectionString" connectionString="Data Source=HAJAN\SQLEXPRESS;Initial Catalog=DatabaseName;Integrated Security=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>
      Replace: (change the bolded replacing them with your information (your database, your database connection)
    name: yourConnectioStringName
    connectionString="DataSource = YOURNAME\SQLEXPRESS (database connection)
    Initial Catalog=DatabaseName
    IntegratedSecurity = True
    providerName = "System.Data.SqlClient"

     
    If you have any problem or further question or... something else..
    Feel free to reply ;)

    Cheers,
    Hajan

    string theRightAnswer = "Mark As Answer";
    Response.Output.Write("If you've found the right answer, don't forget to '{0}'" , theRightAnswer);
Page 1 of 1 (3 items)