locked
How to get datarow object by column name in aspx file? RRS feed

  • Question

  • User-1070000100 posted

    ***aspx code*****

    <asp:Label ID="Label1" runat="server" Text="Label" CssClass="lblTextTitle">Company Name:</asp:Label><asp:TextBox ID="CpName" runat="server" Columns="45" Text="<%#dtDefault.Columns.IndexOf("CpName")  %>"  ></asp:TextBox> 

    ******************

    In the above aspx code, the compile error  like "The server tag is not correct" comes up when specifying by column name as following to get datarow object,

    Text="<%#dtDefault.rows(0).item("CompName")%>"

    But if specifying by index as following, it successfully gets the datarow object.

    Text="<%#dtDefault.rows(0).item(0)%>"

    My question is, is there any regulation that it can in aspx file comparing to axpx.vb file?

    Thanks in advance.

    Thursday, October 25, 2018 3:18 AM

Answers

  • User-1070000100 posted

    I have been given the solution in an other site, it was all about the dboule quotation.it's been successfully done changing to first double quotation to single as Text='<%#dtDefault.rows(0)("CompName") %>'

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 25, 2018 12:16 PM

All replies

  • User-1070000100 posted

    I have been given the solution in an other site, it was all about the dboule quotation.it's been successfully done changing to first double quotation to single as Text='<%#dtDefault.rows(0)("CompName") %>'

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 25, 2018 12:16 PM
  • User61956409 posted

    Hi nac1234,

    Welcome to to ASP.NET forums.

    changing to first double quotation to single as Text='<%#dtDefault.rows(0)("CompName") %>'

    Glad to hear that you solve the problem by yourself, and thanks for sharing the solution to help other community members solve similar problems.

    Besides, if we use Data-binding expressions create bindings between any property on an ASP.NET page, we need use the Page.DataBind or the Control.DataBind method to bind the data to the data sources.

    With Regards,

    Fei Han

    Friday, October 26, 2018 2:53 AM