-1

Im working on a web application in which I need to show data from MySQL on page scroll. In my codebehind I have a [WebMethod] GetData() which connects to MySQL_DB. However I could only able to show first column in my table, below is the code. I want to show a complete table or specific columns. How can I achieve this??

CodeBehind

[WebMethod]
public static string GetDataFromServer()
{
    DataSet ds = new DataSet();
    string connString = "conString";
    MySqlConnection mycon = new MySqlConnection(connString);
    MySqlCommand cmd = new MySqlCommand("select * from rest", mycon);
    MySqlDataAdapter adp = new MySqlDataAdapter(cmd);

    int retVal = adp.Fill(ds);

    string resp = string.Empty;
    for (int i = 1; i <= ds.Tables[0].Rows.Count; i++)
    {
        string strComment = string.Empty;
        if (ds.Tables != null)
        {
            if (ds.Tables[0] != null)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count >= i - 1)
                    {
                        if (ds.Tables[0].Rows[i - 1][0] != DBNull.Value)
                        {
                            //GridView1.DataSource();
                            strComment = ds.Tables[0].Rows[i - 1][0].ToString();
                        }
                    }
                }
            }
        }
        resp += "<p><span>"  + "</span> " + strComment + "</p>";
    }
    return resp;
}

ASPX

        <div id="wra" style="height:300px;overflow:auto">
            <asp:GridView ID="GridView1" runat="server" ></asp:GridView>
        </div>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Venka Yeluri
  • 45
  • 2
  • 11

2 Answers2

1
class TableName
{
public _columnName
{
get;
set;
}
...
}

Include all columns of a table as above.Then fetch all required records from database. Convert database objects into bean class objects and add it in list

List<TableName> listTableName=new List<TableName>();
TableName objTableName=null;

//make a loop that goes on all fetched records of database objTableName._columnName=yourdatabasecolumnvalue

and objTableName to list inside loop and return list from service

gaurav
  • 128
  • 1
  • 8
0
  • Add a bean class to your solution with field names as according to your DB table.
  • Add [ScriptMethod(ResponseFormat=ResponseFormat.JSON)] and resolve ScriptMethod for getting namespace.
  • Convert database object into bean and return from service.This will return JSON to client.
  • You are using ASP.NET Gridview control.But I think when It will rendered ,we should access with it client side scripting or make simple html table with loop.
  • You should use jQuery-mousewheel to catch the event for scrolling
  • When that event occurs make ajax call,access particular rows from table,make html and append to table
gaurav
  • 128
  • 1
  • 8