How do I add 2 DataSet data tables to one GridView column?

I have two results from a dataset. I want to add both results to one column of gridview. I don't want to merge with the code. Is there any other way to do this?

<asp:TemplateField HeaderText="Entered Date" SortExpression="Date">
                    <ItemTemplate>
                    <div style="text-align: center;">
                        <asp:Label ID="Label3" runat="server" Text='<%# formatDisplayDate(Eval("Date").ToString()) %>'></asp:Label>
                    </div>
                    </ItemTemplate>                    
                </asp:TemplateField>

      

Now I will be back "04/04/2009". I would like to return "04/04/2009-PASSED"

0


a source to share


3 answers


You tried:

formatDisplayDate(Eval("Date").ToString()) & "-" & Eval("OtherField").ToString()

      

If that doesn't work, you should be able to set the TemplateField for the combined rows like this:



<asp:TemplateField HeaderText="CombinedFieldName" SortExpression="CombinedFieldName">
    <ItemTemplate>
       <asp:Label ID="Label1" runat="server" 
       Text='<%# DataBinder.Eval(Container,"DataItem.FirstField") %>' >
       </asp:Label>
       -
       <asp:Label ID="Label2" runat="server" 
       Text='<%# DataBinder.Eval(Container,"DataItem.SecondField") %>' >
       </asp:Label>
        </ItemTemplate>
</asp:TemplateField>

      

However, it is generally much more efficient to perform field concatenation in a database operation, if possible. I have not tested, but I would assume that concatenation in SELECT would be the fastest, followed by concatenation in the dataset in code, and concatenation in the ASP.Net page would be the slowest.

+4


a source


Another option is to create a calculated column in the DataTable using the DataColumn.Expression property



0


a source


My first question is, why don't you want to merge with the code? The more content you bind to a control, the more data gets into that control view state.

@ Gary.Ray has a really good solution, but your best bet is to use linq to create a single data object from existing datasets in such a way that you only include what you need and the data is much easier to isolate, think about a single responsibility scheme here if you can move the code that deals with fetching your data somewhere that only deals with fetching the data, your application will be very easy to maintain in the future.

0


a source







All Articles