Two questions: datagrid with string[] and how to differentiate between columns

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Two questions: datagrid with string[] and how to differentiate between columns

    This is my first attempt at creating an ASP.Net app and first using the
    datagrid. Seems pretty nice but there are some peculiarities I can't figure
    out.

    Basically, I want a 3 column datagrid. The first column will list some
    files with the header text set to "File List." The second will be a button
    column with the word "View" to display the file in the browser as html. The
    third will also be a button column with the word "Download" to, you guessed
    it, download the selected file.

    My questions are:

    1. I would like to bind the datagrid directly to
    System.IO.Directory.GetFiles() which returns a string[]. The following
    works to a point:

    -------------------------
    <snip>
    <asp:DataGrid id="dgPickup" runat="server" AutoGenerateColumns="true"
    style="Z-INDEX: 110; LEFT: 72px; POSITION: absolute; TOP: 504px">
    <Columns>
    <asp:ButtonColumn Text="View" HeaderText="View"/>
    <asp:ButtonColumn Text="Download" HeaderText="Download"/>
    </Columns>
    </asp:DataGrid>
    </snip>
    --------------------------

    The file list is in the third column and labelled "Item;" I would like it
    to be the first column and labeled "File List." I have tried many ways to
    create a bound column but cannot figure out how to bind it to the string[].


    2. How do I determine what the user has selected? I can find the row
    using the DataGridCommandEventArgs.Item.ItemIndex, .Cells(), and/or
    ..UniqueID but I don't know how to determine which column within the row
    (view or download) that was selected.



    Last, this is just a newbie asp question, if the user clicks a view button,
    how do i redirect processing to another page passing it the name of the
    file?


    Thanks for any help,
    bob


    Bob Weiner Guest

  2. Similar Questions and Discussions

    1. How to differentiate ASP page Refresh versus Requested by other pa
      Hi ASP Expert, I encounter a page reload situation in ASP. It is I need a way to differentiate whether the current page -...
    2. Add columns to datagrid on the fly!
      I have a datagrid in an ASp.net application. Only one column is created at design time, rest of the columns are created and added to grid on the...
    3. How to add a Dropdown list to a datagrid at runtime (dynamic) without using template columns in ASP.NET and still have the ability to us the datagrid Update event.
      How to add a Dropdown list to a datagrid at runtime (dynamic) without using template columns in ASP.NET and still have the ability to us the...
    4. resizing columns questions
      I want to resize several columns in a table without changing the width size of the entire table. I understand that I can hold down the shift key...
    5. Columns and Inherited Datagrid...Active Schema does not support columns
      I have a class which has inherited from datagrid, to provide some custom functionality, row select, mouse overs etc All is working fine apart from...
  3. #2

    Default Two questions: datagrid with string[] and how to differentiate between columns

    Hi Bob,

    Let's discuss your questions one by one

    Q1:
    You can use
    datagrid.DataSource = System.IO.Directory.GetFiles(path);
    datagrid.DataBind();
    to bind data source.

    Q2:

    Normally the ItemCommand event handles any button click.
    If you assign CommandName for a ButtonColumn, e.g.
    <asp:ButtonColumn Text="View" HeaderText="View"
    CommandName="View" />
    then in ItemCommand you can find out clicked column by
    if (e.CommandName.Equals("View"))
    {
    // View Column clicked
    }

    Q3:
    You use e.Item.Cells[0].Text to get file name in the first
    column. And redirect to a new page:
    Response.Redirect("newpage.aspx?file=" + e.Item.Cells
    [0].Text);


    HTH

    Elton Wang
    [email]elton_wang@hotmail.com[/email]
    >-----Original Message-----
    >This is my first attempt at creating an ASP.Net app and
    first using the
    >datagrid. Seems pretty nice but there are some
    peculiarities I can't figure
    >out.
    >
    >Basically, I want a 3 column datagrid. The first column
    will list some
    >files with the header text set to "File List." The
    second will be a button
    >column with the word "View" to display the file in the
    browser as html. The
    >third will also be a button column with the
    word "Download" to, you guessed
    >it, download the selected file.
    >
    >My questions are:
    >
    > 1. I would like to bind the datagrid directly to
    >System.IO.Directory.GetFiles() which returns a string[].
    The following
    >works to a point:
    >
    >-------------------------
    ><snip>
    > <asp:DataGrid id="dgPickup" runat="server"
    AutoGenerateColumns="true"
    > style="Z-INDEX: 110; LEFT: 72px; POSITION: absolute;
    TOP: 504px">
    > <Columns>
    > <asp:ButtonColumn Text="View" HeaderText="View"/>
    > <asp:ButtonColumn Text="Download"
    HeaderText="Download"/>
    > </Columns>
    > </asp:DataGrid>
    ></snip>
    >--------------------------
    >
    >The file list is in the third column and
    labelled "Item;" I would like it
    >to be the first column and labeled "File List." I have
    tried many ways to
    >create a bound column but cannot figure out how to bind
    it to the string[].
    >
    >
    > 2. How do I determine what the user has selected? I
    can find the row
    >using the DataGridCommandEventArgs.Item.ItemIndex, .Cells
    (), and/or
    >..UniqueID but I don't know how to determine which column
    within the row
    >(view or download) that was selected.
    >
    >
    >
    >Last, this is just a newbie asp question, if the user
    clicks a view button,
    >how do i redirect processing to another page passing it
    the name of the
    >file?
    >
    >
    >Thanks for any help,
    >bob
    >
    >
    >.
    >
    Elton W Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139