locked
how to create a table? RRS feed

  • Question

  • User1022671930 posted

    hi all,

    i want to create a table in asp.net webapplication. The table should consists of several rows and columns. I want to insert heading in each of the column and all the row should be editable and saved. Can anybody please help me regarding.

    thanks in advance

    Tuesday, June 16, 2009 11:55 PM

Answers

All replies

  • User-744022866 posted

    If my guess is correct, your requirement looks similar to gridview webserver control. Have a look at http://msdn.microsoft.com/en-us/beginner/bb308873.aspx

     or if you want to create a table from code behind, then you can use like

    Table t = new Table();
    TableRow tr = new TableRow();
    TableCell td = new TableCell();
    td.Text = "sample";
    tr.Cells.Add(td);
    td = new TableCell();
    tr.Cells.Add(td);
    //..............................
    //..............................
    t.Rows.Add(tr);

    // Add another row
    tr = new TableRow();
    //...............................
    t.Rows.Add(tr);
     //           ......................
    //at the end add the table to the page
    Page.Controls.Add(t);
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 17, 2009 12:57 AM
  • User1162141917 posted

    Hello

    Refer Link: http://www.dotnetcurry.com/ShowArticle.aspx?ID=135

    Thanks 

    Wednesday, June 17, 2009 1:03 AM
  • User-1034726716 posted

    i want to create a table in asp.net webapplication. The table should consists of several rows and columns. I want to insert heading in each of the column and all the row should be editable and saved. Can anybody please help me regarding.
     

    Why not use GridView Control instead? Check this example: Adding Dynamic Rows in GridView with TextBoxes

    and this example: Adding Rows in GridView with Edit, Update and Delete Functionality

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 17, 2009 1:52 AM
  • User1022671930 posted

    hi all,

    thank you for ur reply. I have used grid view and sql data source to create the table. The table is created and the value is displaying the table from the database. Now the problem is , when i tried to edit one of the field and then pressing update button, i am getting the following error.

    Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query

    Can anybody please help me to resolve this.

    thanks in advance

    Thursday, June 18, 2009 6:25 AM
  • User1022671930 posted

    hi all,

    I am using sqldatasoure for loading the values to the grid view table. When i edit one particular column in the grid view table, i want to read that value into one particular variable. Can anybody please help me to write a code  for that..

     

    thanks

     

    Thursday, June 18, 2009 9:50 AM
  • User-1034726716 posted

    Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query
     

    Check your update parameters, be sure that the parameter you pass in your query matches the datatype of the column in your database.. 

    for example if you have a column in your database called Column1 with a datatype of varchar then you should pass a string type to that column in your codes..

    Thursday, June 18, 2009 9:49 PM
  • User1383809551 posted

    Hi,

    Uou can select the value in a cell by

    string myVar = GridView.Rows[e.NewEditIndex].Cells[yourcellindexhere].Text;

     

    Thanks

    Ratheesh

    Thursday, June 18, 2009 10:20 PM
  • User-1034726716 posted

    When i edit one particular column in the grid view table, i want to read that value into one particular variable
     

    You can use RowUpdating event to read the edited value like:

     

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
       //Accessing Edited values from the GridView
       string value= ((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text;
    }
      
    Thursday, June 18, 2009 10:34 PM
  • User1022671930 posted

    hi vinz,

    thank you for your reply. But still i am finding difficult in getting the value of particular row which has been edited. Can you please help me to write a code for row updating  to get the value from the gridview table. I have used sql datasource to load the table.

    thanks

    Thursday, June 18, 2009 11:18 PM
  • User-1034726716 posted

    But still i am finding difficult in getting the value of particular row which has been edited. Can you please help me to write a code for row updating  to get the value from the gridview table.
     

    The code that I have provided is basically getting the edited value at RowUpdating event.

    I have used sql datasource to load the table.
     

    If you are using SDS as you datasource and you have set Update on it then you don't have to write some codes for updating the rows in GridView because the SDS will take care of that for you..

    See this article for example: http://www.highoncoding.com/Articles/83_In_place_Updating_and_Deleting_in_GridView.aspx

    and this article: http://www.codersource.net/asp_net_grid_view_whidbey.aspx

    Thursday, June 18, 2009 11:37 PM
  • User1022671930 posted

    hi vinz,

    thanks again for your reply. Now i am able to update the gridview table. My next step is to add a new row to the same gridview table  by clicking the button add new row and it should take some values and it should update the table.Can you please help me regarding this

    thanks once again

    Friday, June 19, 2009 2:43 AM
  • User-1034726716 posted

    hi vinz,

    thanks again for your reply. Now i am able to update the gridview table.

     

    Great! :)

    My next step is to add a new row to the same gridview table  by clicking the button add new row and it should take some values and it should update the table.Can you please help me regarding this
     

    Something like this?

    How to easily insert row in GridView with SqlDataSource?

    Friday, June 19, 2009 2:49 AM
  • Friday, June 19, 2009 6:02 AM
  • User1022671930 posted

    hi all,

    The gridview table which i have used is getting all the rows and colums from the database and displaying it in a web page. But i want to display only the seleted rows from the database in grid view table. Can anybody please help me regarding this..

    thanks

    Monday, June 22, 2009 12:39 AM
  • User-1034726716 posted

    But i want to display only the seleted rows from the database in grid view table. Can anybody please help me regarding this..
     

    You can change your query for binding your GridView to filter out the selected rows from the database like.. 

    SELECT * FROM <TableName> WHERE IsSelected = true

    Monday, June 22, 2009 1:26 AM
  • User1022671930 posted

    hi vinz,

     Thank for your reply.. I have loaded all the username to the dropdownlist. Based on the selection of the username in the dropdownlist, i have to display only that persons details in the gridview table. Every time i change the username in the dropdownlist, the gridview table should update. How can i make it possible. Where exactly i can write a query for this? Can you please help me regarding this..

    thanks

    Monday, June 22, 2009 1:45 AM
  • User-1034726716 posted

    I have loaded all the username to the dropdownlist. Based on the selection of the username in the dropdownlist, i have to display only that persons details in the gridview table. Every time i change the username in the dropdownlist, the gridview table should update. How can i make it possible. Where exactly i can write a query for this? Can you please help me regarding this..
     

    You can use the FilterExpression and set up the FilterParameters of SqlDataSource that points to the DropDownList to filter the Gridview based on the DDL selected value.

    Also See: Show GridView against DropDownList Value 

    Monday, June 22, 2009 2:10 AM
  • User1022671930 posted

    hi vinz,

    Since i am new to this gridview, i dont know much about filter express and filter parameters. Can u please help me with some code asap.

    thanks

    Monday, June 22, 2009 2:39 AM
  • User-1034726716 posted

    Since i am new to this gridview, i dont know much about filter express and filter parameters. Can u please help me with some code asap.
     

    Have you tried looking into the links that I posted above about FilterParamters?You should be able to find more info with examples there..I will post the link again below:

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.filterparameters.aspx

    Monday, June 22, 2009 2:54 AM
  • User169219854 posted

    Hi,

     Here is you code:

    Table newTable = new Table();

    TableRow trHeader = new TableRow();
    TableCell tdHeader = new TableCell();

    tdHeader.Text = "Header Text 1 goes here";
    trHeader.Cells.Add(tdHeader);

    tdHeader = new TableCell();
    tdHeader.Text = "Header Text 2 goes here";
    trHeader.Cells.Add(tdHeader);
    // you can add other header coloumns here

    newTable.Rows.Add(trHeader);

    // Add content row
    TableRow tr = new TableRow();
    TableCell td = new TableCell();

    td.Text = "Content Text 1 goes here";
    tr.Cells.Add(td);

    td = new TableCell();
    td.Text = "Content Text 2 goes here";
    tr.Cells.Add(td);
    // you can add other content coloumns here or you can use loop

    newTable.Rows.Add(tr);
    Page.Controls.Add(newTable);

      

    Mark it as answer if it helps you.

    Thanks

    Monday, June 22, 2009 3:40 AM
  • User-1034726716 posted

    Hi,

     Here is you code:

    Table newTable = new Table();

    TableRow trHeader = new TableRow();
    TableCell tdHeader = new TableCell();

    tdHeader.Text = "Header Text 1 goes here";
    trHeader.Cells.Add(tdHeader);

    tdHeader = new TableCell();
    tdHeader.Text = "Header Text 2 goes here";
    trHeader.Cells.Add(tdHeader);
    // you can add other header coloumns here

    newTable.Rows.Add(trHeader);

    // Add content row
    TableRow tr = new TableRow();
    TableCell td = new TableCell();

    td.Text = "Content Text 1 goes here";
    tr.Cells.Add(td);

    td = new TableCell();
    td.Text = "Content Text 2 goes here";
    tr.Cells.Add(td);
    // you can add other content coloumns here or you can use loop

    newTable.Rows.Add(tr);
    Page.Controls.Add(newTable);

      

    Mark it as answer if it helps you.

     

    Hi

    Have you read all the post in this thread? The issue now is not about creating a Table..

    Monday, June 22, 2009 4:12 AM
  • User1022671930 posted

    hi vinz,

    I had gone through your filter expression link. But i have got one problem in using that. ie. the filter expression works based on the value given in the dropdownlist. If the dropdownlist contains 1, 2 , 3 and if i select 2 then it is going to get the data from the DB of the column which i have given in the filter parameters corresponding to the value 2. But in my case, i am comparing two dropdownlist  and  wil get a particular user id in the DB and then i will check in grid table for that user id to display data. This id is getting from other DB table based on the selection of dropdownlist. Then i want the particular row correponding to this id not the one in the ddl. Is it possible to make grid view work like this?

    Tuesday, June 23, 2009 4:41 AM