Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public void binddata()
    {
        DataTable dt = new DataTable();
        SqlCommand com = new SqlCommand("E_R_GET101", con);
        com.Parameters.AddWithValue("@Subs_cd", loggeduser.SUBSIDIARY_CD);
        com.Parameters.AddWithValue("@EMPLOYEE", loggeduser.EmployeeNo);
        com.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter da = new SqlDataAdapter(com);
         con.Open();
         da.Fill(dt);
        getdata.DataSource = dt;
        getdata.DataBind();
        con.Close();
    }

ASP.NET
down vote
favorite
  <li class="dropdown"><a href="#" class="btn btn-info" data-toggle="dropdown">Inbox <span class="badge"  runat="server" style="color: red" id="txtContactCount">0</span> </a>
                <ul class="dropdown-menu" id="getdata"  runat="server">
                    <li class="divider"></li>
                    <li><a href="Portal_noticexD.aspx">View all notifications</a></li>
                </ul>
            </li>

fail to bind data ,where i did wrong??

What I have tried:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Posted
Updated 29-Aug-16 17:26pm

1 solution

Instead of trying to BIND to a dataTable, try a DataSet. It's difficult without seeing the rest of your code, but try this:
C#
public void binddata()
    {
        DataSet ds = new DataSet();
        SqlCommand com = new SqlCommand("E_R_GET101", con);
        com.Parameters.AddWithValue("@Subs_cd", loggeduser.SUBSIDIARY_CD);
        com.Parameters.AddWithValue("@EMPLOYEE", loggeduser.EmployeeNo);
        com.CommandType = CommandType.StoredProcedure;
        con.Open();        
        SqlDataAdapter da = new SqlDataAdapter(com);         
        da.Fill(ds);
        getdata.DataSource = ds;
        getdata.DataBind();
        con.Close();
    }

The DataBind method ensures the datasource is bound to the control, however, since you databind within the getdata.DataSource context, the control should read the data from the datasource without the need for the DataBind Method... comment out the DataBind and see what happens.
C#
//getdata.DataBind();

Another option is to call .ToList() method. This sets the DataSource property to a list containing the data.
C#
getdata.DataSource = ds.ToList();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900