Connecting Tech Pros Worldwide Help | Site Map

fill a datagrid

Newbie
 
Join Date: Nov 2009
Posts: 1
#1: 2 Weeks Ago
Hiii
I have a one textbox ,one button,one datagridm i want to fill datagrid anything type in textbox and press button than whatever value in text box is going to datagrid and so on and i don't use any databe connection just fill the datagrid throgh textbox.text value


thank u
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#2: 2 Weeks Ago

re: fill a datagrid


Wow I'm not sure what you want to do.

Am I understanding this correctly:

You have a TextBox and a Button.
The user enters something into the text.
The user clicks the button
The system displays the value entered by the user into a GridView control.

The user clicks a button in the GridView control
The system retrieves the text from the row that the user clicked the button in
The system displays the text in the TextBox.


-Frinny
ThatThatGuy's Avatar
Member
 
Join Date: Jul 2009
Location: Mumbai--India
Posts: 39
#3: 2 Weeks Ago

re: fill a datagrid


it's pretty simple
for a datagrid to fill from a virtual data....
you need to create a data table and assign it to the DataSource property of the datagrid....
do this
Expand|Select|Wrap|Line Numbers
  1. DataTable dt;
  2.  
Declare this datatable as a class member

now on page load create the structure of the datatable like this
Expand|Select|Wrap|Line Numbers
  1. dt=new DataTable("Sample")
  2. dt.Columns.Add(new DataColumn("Header"));
  3.  
Now this is done add this code in the button's click event
Expand|Select|Wrap|Line Numbers
  1. DataRow dr=dt.Rows.NewRow();
  2. dr[0]=textBox1.Text;
  3. dt.Rows.Add(dr);
  4. DataGrid1.DataSource=dt;
  5. DataGrid1.DataBind();
  6.  
What i have done this is whenever you press the button a row is added to the datatable with the updated value in the textbox.... and then again the updated datasource is assigned to the datagrid....
and since it's on the Web...
DataGrid1.DataBind();
has to be done otherwise it will not show the updated result....

hope that's the thing you wanted
maliksleo's Avatar
Member
 
Join Date: Feb 2009
Location: Islamabad, Pakistan
Posts: 115
#4: 1 Week Ago

re: fill a datagrid


hi
simply place some label in grid and assign the value of textbox to that label on click like
Expand|Select|Wrap|Line Numbers
  1. gridview1.row(0).findcontrol(label1,label).text
and assign the value to it.

maliksleo
Reply