You must Sign In to post a response.
  • Category: ASP.NET

    The name 'getStudentData' does not exist in the current context

    hi,

    I am trying bind database to hmtl. Because i want use bootstrap datatable jquery.
    I am getting following error. I found this coding in online.

    'The name 'getStudentData' does not exist in the current context'

    <head runat="server">
    <meta charset="utf-8" />
    <title>Employees Data Fill From Database</title>
    <meta name="description" content="Creating a Employee table with Twitter Bootstrap. Learn with example of a Employee Table with Twitter Bootstrap.">
    <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"
    rel="stylesheet" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <link href="http://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css" rel="stylesheet" />
    <script type="text/javascript" src="http://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    <%-- <script type="text/javascript">
    $(document).ready(function () {
    $('#studentTable').dataTable();
    });
    </script>--%>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <table id="studentTable" width="100%" align="center" cellpadding="2" cellspacing="2"
    border="0" bgcolor="#EAEAEA">
    <tr align="left" style="background-color: #004080; color: White;">
    <td>
    StudentId
    </td>
    <td>
    Name
    </td>
    <td>
    EmailAddress
    </td>
    <td>
    Gender
    </td>
    </tr>
    <%=getStudentData()%>
    </table>
    </div>
    </form>
    </body>

    private string getStudentData()
    {
    string data = "";
    int incVal;
    int Sl;
    int datas;
    int heading1;
    int heading2;

    DataTable dt = new DataTable();

    dt.Columns.Add("Sl");
    dt.Columns.Add("datas");
    dt.Columns.Add("heading1");
    dt.Columns.Add("heading2");

    for (int i = 0; i < 100; i++)
    {
    dt.Rows.Add(new object[] { i, 123 * i, 4567 * i, 2 * i, });
    }

    for (incVal = 0; incVal < dt.Rows.Count; incVal++)
    {
    Sl = Convert.ToInt32(dt.Rows[incVal]["Sl"].ToString());
    datas = Convert.ToInt32(dt.Rows[incVal]["datas"].ToString());
    heading1 = Convert.ToInt32(dt.Rows[incVal]["heading1"].ToString());
    heading2 = Convert.ToInt32(dt.Rows[incVal]["heading2"].ToString());

    data += "<tr><td>" + Sl + "</td><td>" + datas + "</td><td>" + heading1 + "</td><td>" + heading2 + "</td></tr>";
    }

    return data;
    }
  • #768653
    Hi,

    I feel the access specifier might be a problem in the getStudentData() declaration.
    I think you need to modify the access specifier depend on your requirement. You can declaring this function in code behind page, it's modifiers must be internal, protected or public.

    Thanks,
    Mani

  • #768670
    Hi,

    Try use like below


    <%# getStudentData()%>


    and use the access modifier protected, it works for me.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments