Search code examples
asp.netdata-bindingdatalist

Adding 2 values to parameter when databinding using DataList in ASP.NET


I have the code

 <asp:DataList ID="DataList1" runat="server" 
       DataKeyField="TextId" OnEditCommand="DataList1_EditCommand"
       OnCancelCommand="DataList1_CancelCommand" 
       OnDeleteCommand="DataList1_DeleteCommand" 
       OnUpdateCommand="DataList1_UpdateCommand">
     <EditItemTemplate>
         <asp:TextBox Runat="server" ID="TheNotes"
             Text='<%# Bind("notes") %>' />
     </EditItemTemplate>
 </asp:DataList>

What i want to do is bind 2 variables to one control

  <asp:TextBox Runat="server" ID="TheNotes"
     Text='<%# Bind("notes") Bind("dates")  %>' />

Anyone know how to do this ? without it erroring, they are both in the control datasource


Solution

  • You can do it by using the below 3 solutions

    Solution 1 :

    <asp:TextBox Runat="server" ID="TheNotes"
         Text='<%# Bind("notes") + Bind("dates")  %>' />
    

    Solution 2 :

    You can do one more things, u can select two column as a single column in sql select query.

    SELECT (ColumnA + ColumnB) AS ColumnZ
    FROM Table;
    

    and then bind it with single control

    Solution 3:

    bind multiple data to itemtemplate in gridview using Row data bound

    And

    using string format