fill a datagrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rushi Panchal
    New Member
    • Nov 2009
    • 1

    fill a datagrid

    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
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    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

    Comment

    • ThatThatGuy
      Recognized Expert Contributor
      • Jul 2009
      • 453

      #3
      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
      Code:
      DataTable dt;
      Declare this datatable as a class member

      now on page load create the structure of the datatable like this
      Code:
      dt=new DataTable("Sample")
      dt.Columns.Add(new DataColumn("Header"));
      Now this is done add this code in the button's click event
      Code:
      DataRow dr=dt.Rows.NewRow();
      dr[0]=textBox1.Text;
      dt.Rows.Add(dr);
      DataGrid1.DataSource=dt;
      DataGrid1.DataBind();
      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.DataB ind();
      has to be done otherwise it will not show the updated result....

      hope that's the thing you wanted

      Comment

      • maliksleo
        New Member
        • Feb 2009
        • 115

        #4
        hi
        simply place some label in grid and assign the value of textbox to that label on click like
        Code:
        gridview1.row(0).findcontrol(label1,label).text
        and assign the value to it.

        maliksleo

        Comment

        Working...