0

Could anyone tell me whether datagrid in asp.net can be used without database bcos if it is used means not visible during runtime.. anyone can advise if u know in this regard.........

4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by rispy
2

DataGrids, Repeaters, etc., do not have to be used with database connections, they can be bound with other collections. Take this example:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DataGrid ID="myDatagrid" AutoGenerateColumns="true" runat="server">
        </asp:DataGrid>
    </div>
    </form>
</body>
</html>

And the code behind

protected void Page_Load(object sender, EventArgs e)
    {
        List<string> myStrings = new List<string>() { "A", "B", "C" };
        myDatagrid.DataSource = myStrings;
        myDatagrid.DataBind();
    }

The result here is a simple grid with these results

Item 
A 
B 
C

I hope that's the answer you're looking for? Alternately, DataGrids do not have to bound to anything at all, in which case they'll not even appear when you load the page.

Edited by apegram: n/a

Votes + Comments
Nice to see someone giving examples but not doing peoples' work for them :) Instructive = good!
0

The above post is correct. I want to add when you use arraylist of objects, the public properties of the objects in that arraylist are similar to columns of your SQL queried data.

0

thank you... but i want a grid in such a way that i want text boxes in the grid to enter values and also it automatically increment the rows after pressing enter or tab at the last cell... i have designed the grid but it is not visible at run time..... cud u pls xplain

Edited by prakashmca07: n/a

-1

plz help me,i need it
after receiving the mail when he click on the mail i need to get the mail in asp.net

Votes + Comments
If you have a question please start a thread. Posting in a 2+ year old thread with a new question = not so great ;)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.