locked
Concatenate DataSourceID string and variable RRS feed

  • Question

  • User1878523065 posted

    Hi,

    What is the correct syntax to concatenate a DataSourceID string and a variable?

    If MyVariable = A  I want to have MyAccessDataSourceA

    <asp:DetailsView ID="DetailsView1" DataSourceID="MyAccessDataSource" & MyVariable>



    Thanks.

    Tuesday, May 31, 2011 9:56 PM

Answers

  • User3866881 posted

    Hello:)

    Just to write the binding code at Page_Load event, like this:

      protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    DataList1.DataSourceID = "SqlDataSource1";
                }
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 2, 2011 8:58 PM

All replies

  • User-1542018982 posted

    Hi,

    I think to set it in Code-behind Page_Init event, and the code is like below:

    DetailsView1.DataSourceID = "MyAccessDataSource" & MyVariable

    Hope it helps.

    Tuesday, May 31, 2011 10:08 PM
  • User1878523065 posted

    Actualy I wanted to format my string directly because I'm having an issue with my DataLists' strings declaration. I do nicely with DetailsView and GridView, but not so with DataList.

    Succes: DetailsView1.DataSourceID = "MyString"
    Succes: GridView1.DataSourceID = "MyString"
    Fail: DataList1.DataSourceID = "MyString"

    What's wrong with this DataList that's working with DetailsView and GridView ?

    Wednesday, June 1, 2011 6:41 PM
  • User-1542018982 posted

    Hi,

    As I know, it shouldn't be a problem for DataList.

    Please explain more how DataList is not working. Any exception is thrown?

    Wednesday, June 1, 2011 10:13 PM
  • User1878523065 posted

    My code is on the page itself, between <asp:Content></asp:Content>

    <% DataList1.DataSourceID = "MyString" %>

    <asp:DataList ID="DataList1" runat="server">
      <ItemTemplate>
           <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Logo_Receveurs") %>' />
           <br />
           <asp:Label ID="ButsReceveurs" runat="server"
                  Text='<%# Eval("ButsPourMatchReceveurs") %>'>
            </asp:Label>
            <br />
            <asp:Label ID="PointsReceveurs" runat="server" Text='<%# Eval("PointsPourMatchReceveurs") %>' >
            </asp:Label>
      </ItemTemplate>
    </asp:DataList>

    No exception, the DataList simply doesn't display. Not because of a Null value. A Response.Write test shows the correct string.

    Thursday, June 2, 2011 6:03 PM
  • User3866881 posted

    Hello:)

    Just to write the binding code at Page_Load event, like this:

      protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    DataList1.DataSourceID = "SqlDataSource1";
                }
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 2, 2011 8:58 PM