views:

391

answers:

2

hi,I developing a mobile web application where i need to display data retrieved from database to a grid or datatable in .net.i have tried out with list but it is not serving my pupose as i ned to siaplay multiple columns and rows fetched from the databse.

Thanks in advance!!

A: 

Have you tried outputting the data into a table? Tables are designed to display data in rows and columns in the way that you're after. Lists are designed for showing only one column (or row) of data.

James
A: 

You can use the following code to bind data to a gridview in mobile apps:
In .aspx page:

<mobile:Form id="Form1" runat="server" Paginate="true"  >    
        <mobile:DeviceSpecific ID="mobdevspec" Runat="Server" >
          <Choice Xmlns="http://schemas.microsoft.com/mobile/html32template"&gt;
            <HeaderTemplate>             
                  <asp:GridView ID="GridView1" runat="server"></asp:GridView>                   
            </HeaderTemplate>
          </Choice>
        </mobile:DeviceSpecific>
    </mobile:Form>

In .aspx.cs file:

GridView gv = (GridView)Form1.Controls[0].FindControl("gridview");
// gv.GridLines = true;
SqlConnection con = new SqlConnection("Data Source=WINSERVER;Initial      Catalog=sampleDB;User Id=orbtest; password=hyderabad");
con.Open();
string sqlquery = "SELECT * FROM anderson";
SqlCommand command = new SqlCommand(sqlquery, con);
SqlDataAdapter adpa = new SqlDataAdapter(command);

DataTable dt = new DataTable();

adpa.Fill(dt);        

gv.DataSource = dt;
gv.DataBind();
con.Close();
Abhimanyu