Binding errors on unused columns

T

tshad

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
 
G

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

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
 
E

Eliyahu Goldin

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 said:
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
 
G

Gregory A. Beamer

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,
 
T

tshad

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
 
T

tshad

Eliyahu Goldin said:
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 said:
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
 
T

tshad

Gregory A. Beamer said:
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
 
G

Gregory A. Beamer

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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top