Binding errors on unused columns

Discussion in 'ASP .Net' started by tshad, Sep 30, 2009.

  1. tshad

    tshad Guest

    I want to use the same grid for 2 different stored procedures. The problem
    is that some columns are not in the second SP. I would hide these columns
    if running in that mode. The problem is that I would get errors from the
    columns in the grid that don't have any columns in the returned SP to bind
    with.

    For example, the TrackingCode would not be in the other stored procedure so
    this template would give me an error. I could either create another
    identical Grid without these field but then I would have to keep track of
    which Grid I was dealing with.

    <asp:TemplateField HeaderText="Tracking Code"
    HeaderStyle-CssClass="GridViewHeader" SortExpression="TrackingCode" >
    <ItemTemplate>
    <asp:Label ID="lblTrackingCode" runat="server" Text='<%#
    Eval("TrackingCode") %>'></asp:Label>
    </ItemTemplate><EditItemTemplate>
    <asp:TextBox ID="txtTrackingCode" runat="server" Width="80px"
    Text='<%# Eval("TrackingCode") %>' />
    </EditItemTemplate>
    </asp:TemplateField>

    Is there a way to tell the program at Binding time to ignore these columns
    since they are going to be invisible anyway?

    Thanks,

    Tom
    tshad, Sep 30, 2009
    #1
    1. Advertising

  2. On Oct 1, 12:40 am, "tshad" <> wrote:
    > I want to use the same grid for 2 different stored procedures.  The problem
    > is that some columns are not in the second SP.  I would hide these columns
    > if running in that mode.  The problem is that I would get errors from the
    > columns in the grid that don't have any columns in the returned SP to bind
    > with.
    >
    > For example, the TrackingCode would not be in the other stored procedure so
    > this template would give me an error.  I could either create another
    > identical Grid without these field but then I would have to keep track of
    > which Grid I was dealing with.
    >
    > <asp:TemplateField HeaderText="Tracking Code"
    > HeaderStyle-CssClass="GridViewHeader" SortExpression="TrackingCode" >
    >   <ItemTemplate>
    >       <asp:Label ID="lblTrackingCode" runat="server" Text='<%#
    > Eval("TrackingCode") %>'></asp:Label>
    >   </ItemTemplate><EditItemTemplate>
    >       <asp:TextBox ID="txtTrackingCode" runat="server" Width="80px"
    > Text='<%# Eval("TrackingCode") %>' />
    >   </EditItemTemplate>
    > </asp:TemplateField>
    >
    > Is there a way to tell the program at Binding time to ignore these columns
    > since they are going to be invisible anyway?
    >
    > Thanks,
    >
    > Tom


    You will still bind them even they are invisible. Either change your
    second stored procedure to return all columns, e.g.

    SELECT ...., NULL as TrackingCode FROM.....

    or add columns programmatically
    Alexey Smirnov, Oct 1, 2009
    #2
    1. Advertising

  3. Can you modify the sp to return the missing columns will null values? This
    is the simplest way.

    Another way is to make a typed dataset and fill it ap with a data adapter.
    Data adapters provide a property MissingSchemaAction. The default value is
    Add which is "Adds the necessary columns to complete the schema."

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://blogs.microsoft.co.il/blogs/egoldin
    http://msmvps.com/blogs/egoldin


    "tshad" <> wrote in message
    news:...
    >I want to use the same grid for 2 different stored procedures. The problem
    >is that some columns are not in the second SP. I would hide these columns
    >if running in that mode. The problem is that I would get errors from the
    >columns in the grid that don't have any columns in the returned SP to bind
    >with.
    >
    > For example, the TrackingCode would not be in the other stored procedure
    > so this template would give me an error. I could either create another
    > identical Grid without these field but then I would have to keep track of
    > which Grid I was dealing with.
    >
    > <asp:TemplateField HeaderText="Tracking Code"
    > HeaderStyle-CssClass="GridViewHeader" SortExpression="TrackingCode" >
    > <ItemTemplate>
    > <asp:Label ID="lblTrackingCode" runat="server" Text='<%#
    > Eval("TrackingCode") %>'></asp:Label>
    > </ItemTemplate><EditItemTemplate>
    > <asp:TextBox ID="txtTrackingCode" runat="server" Width="80px"
    > Text='<%# Eval("TrackingCode") %>' />
    > </EditItemTemplate>
    > </asp:TemplateField>
    >
    > Is there a way to tell the program at Binding time to ignore these columns
    > since they are going to be invisible anyway?
    >
    > Thanks,
    >
    > Tom
    >
    >
    > __________ Information from ESET NOD32 Antivirus, version of virus
    > signature database 4471 (20090930) __________
    >
    > The message was checked by ESET NOD32 Antivirus.
    >
    > http://www.eset.com
    >
    >
    >



    __________ Information from ESET NOD32 Antivirus, version of virus signature database 4472 (20091001) __________

    The message was checked by ESET NOD32 Antivirus.

    http://www.eset.com
    Eliyahu Goldin, Oct 1, 2009
    #3
  4. "tshad" <> wrote in
    news::

    > I want to use the same grid for 2 different stored procedures. The
    > problem is that some columns are not in the second SP. I would hide
    > these columns if running in that mode. The problem is that I would
    > get errors from the columns in the grid that don't have any columns in
    > the returned SP to bind with.
    >
    > For example, the TrackingCode would not be in the other stored
    > procedure so this template would give me an error. I could either
    > create another identical Grid without these field but then I would
    > have to keep track of which Grid I was dealing with.
    >
    > <asp:TemplateField HeaderText="Tracking Code"
    > HeaderStyle-CssClass="GridViewHeader" SortExpression="TrackingCode" >
    > <ItemTemplate>
    > <asp:Label ID="lblTrackingCode" runat="server" Text='<%#
    > Eval("TrackingCode") %>'></asp:Label>
    > </ItemTemplate><EditItemTemplate>
    > <asp:TextBox ID="txtTrackingCode" runat="server" Width="80px"
    > Text='<%# Eval("TrackingCode") %>' />
    > </EditItemTemplate>
    > </asp:TemplateField>
    >
    > Is there a way to tell the program at Binding time to ignore these
    > columns since they are going to be invisible anyway?


    I would set up the Grid with the common columns. Then add the extra
    columns when using stored procedure 1 (programatically, that is).

    Either that, or define each column with each hit and then fill. This is
    the more explicit route and gives you more thorough control of the
    placement of extra columns. It is most useful if the extra columns need
    to be in the middle of the grid.

    Peace and Grace,


    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
    Gregory A. Beamer, Oct 1, 2009
    #4
  5. tshad

    tshad Guest

    "Alexey Smirnov" <> wrote in message
    news:...
    On Oct 1, 12:40 am, "tshad" <> wrote:
    > I want to use the same grid for 2 different stored procedures. The problem
    > is that some columns are not in the second SP. I would hide these columns
    > if running in that mode. The problem is that I would get errors from the
    > columns in the grid that don't have any columns in the returned SP to bind
    > with.
    >
    > For example, the TrackingCode would not be in the other stored procedure
    > so
    > this template would give me an error. I could either create another
    > identical Grid without these field but then I would have to keep track of
    > which Grid I was dealing with.
    >
    > <asp:TemplateField HeaderText="Tracking Code"
    > HeaderStyle-CssClass="GridViewHeader" SortExpression="TrackingCode" >
    > <ItemTemplate>
    > <asp:Label ID="lblTrackingCode" runat="server" Text='<%#
    > Eval("TrackingCode") %>'></asp:Label>
    > </ItemTemplate><EditItemTemplate>
    > <asp:TextBox ID="txtTrackingCode" runat="server" Width="80px"
    > Text='<%# Eval("TrackingCode") %>' />
    > </EditItemTemplate>
    > </asp:TemplateField>
    >
    > Is there a way to tell the program at Binding time to ignore these columns
    > since they are going to be invisible anyway?
    >
    > Thanks,
    >
    > Tom
    >
    >You will still bind them even they are invisible. Either change your
    >second stored procedure to return all columns, e.g.
    >
    >SELECT ...., NULL as TrackingCode FROM.....
    >

    Actually, that was what I was going to do if I couldn't do that in the
    Markup.

    I am also thinking of just creating a 2nd Grid for this purpose and just
    bind to the correct grid.

    >or add columns programmatically


    I would need to redo my code to handle that and I would just prefer to deal
    with what I have.

    Thanks,

    Tom
    tshad, Oct 1, 2009
    #5
  6. tshad

    tshad Guest

    "Eliyahu Goldin" <> wrote in
    message news:...
    > Can you modify the sp to return the missing columns will null values? This
    > is the simplest way.
    >

    I thinks this what I am going to do.

    Thanks,

    Tom

    > Another way is to make a typed dataset and fill it ap with a data adapter.
    > Data adapters provide a property MissingSchemaAction. The default value is
    > Add which is "Adds the necessary columns to complete the schema."
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://blogs.microsoft.co.il/blogs/egoldin
    > http://msmvps.com/blogs/egoldin
    >
    >
    > "tshad" <> wrote in message
    > news:...
    >>I want to use the same grid for 2 different stored procedures. The
    >>problem is that some columns are not in the second SP. I would hide these
    >>columns if running in that mode. The problem is that I would get errors
    >>from the columns in the grid that don't have any columns in the returned
    >>SP to bind with.
    >>
    >> For example, the TrackingCode would not be in the other stored procedure
    >> so this template would give me an error. I could either create another
    >> identical Grid without these field but then I would have to keep track of
    >> which Grid I was dealing with.
    >>
    >> <asp:TemplateField HeaderText="Tracking Code"
    >> HeaderStyle-CssClass="GridViewHeader" SortExpression="TrackingCode" >
    >> <ItemTemplate>
    >> <asp:Label ID="lblTrackingCode" runat="server" Text='<%#
    >> Eval("TrackingCode") %>'></asp:Label>
    >> </ItemTemplate><EditItemTemplate>
    >> <asp:TextBox ID="txtTrackingCode" runat="server" Width="80px"
    >> Text='<%# Eval("TrackingCode") %>' />
    >> </EditItemTemplate>
    >> </asp:TemplateField>
    >>
    >> Is there a way to tell the program at Binding time to ignore these
    >> columns since they are going to be invisible anyway?
    >>
    >> Thanks,
    >>
    >> Tom
    >>
    >>
    >> __________ Information from ESET NOD32 Antivirus, version of virus
    >> signature database 4471 (20090930) __________
    >>
    >> The message was checked by ESET NOD32 Antivirus.
    >>
    >> http://www.eset.com
    >>
    >>
    >>

    >
    >
    > __________ Information from ESET NOD32 Antivirus, version of virus
    > signature database 4472 (20091001) __________
    >
    > The message was checked by ESET NOD32 Antivirus.
    >
    > http://www.eset.com
    >
    >
    >
    tshad, Oct 1, 2009
    #6
  7. tshad

    tshad Guest

    "Gregory A. Beamer" <> wrote in message
    news:Xns9C9762F9A1B59gbworld@207.46.248.16...
    > "tshad" <> wrote in
    > news::
    >
    >> I want to use the same grid for 2 different stored procedures. The
    >> problem is that some columns are not in the second SP. I would hide
    >> these columns if running in that mode. The problem is that I would
    >> get errors from the columns in the grid that don't have any columns in
    >> the returned SP to bind with.
    >>
    >> For example, the TrackingCode would not be in the other stored
    >> procedure so this template would give me an error. I could either
    >> create another identical Grid without these field but then I would
    >> have to keep track of which Grid I was dealing with.
    >>
    >> <asp:TemplateField HeaderText="Tracking Code"
    >> HeaderStyle-CssClass="GridViewHeader" SortExpression="TrackingCode" >
    >> <ItemTemplate>
    >> <asp:Label ID="lblTrackingCode" runat="server" Text='<%#
    >> Eval("TrackingCode") %>'></asp:Label>
    >> </ItemTemplate><EditItemTemplate>
    >> <asp:TextBox ID="txtTrackingCode" runat="server" Width="80px"
    >> Text='<%# Eval("TrackingCode") %>' />
    >> </EditItemTemplate>
    >> </asp:TemplateField>
    >>
    >> Is there a way to tell the program at Binding time to ignore these
    >> columns since they are going to be invisible anyway?

    >
    > I would set up the Grid with the common columns. Then add the extra
    > columns when using stored procedure 1 (programatically, that is).
    >
    > Either that, or define each column with each hit and then fill. This is
    > the more explicit route and gives you more thorough control of the
    > placement of extra columns. It is most useful if the extra columns need
    > to be in the middle of the grid.
    >

    Sounds like a pretty good Idea and may do that later.

    Right now I need a quick solution and I think passing null for the missing
    columns would be quickest.

    Thanks,

    Tom

    > Peace and Grace,
    >
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > Twitter: @gbworld
    > Blog: http://gregorybeamer.spaces.live.com
    >
    > *******************************************
    > | Think outside the box! |
    > *******************************************
    tshad, Oct 1, 2009
    #7
  8. "tshad" <> wrote in
    news::

    > Right now I need a quick solution and I think passing null for the
    > missing columns would be quickest.


    That is what refactoring is for. :)

    Peace and Grace,

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
    Gregory A. Beamer, Oct 2, 2009
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    942
    Mark Goldin
    Jan 17, 2004
  2. helpful sql
    Replies:
    0
    Views:
    809
    helpful sql
    May 19, 2005
  3. Replies:
    5
    Views:
    594
  4. Replies:
    4
    Views:
    937
  5. =?Utf-8?B?YmVub2l0?=

    Read CSV - string Columns - Int columns

    =?Utf-8?B?YmVub2l0?=, May 8, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    433
    =?Utf-8?B?YmVub2l0?=
    May 8, 2006
Loading...

Share This Page