locked
Retrive data from gridview to textbox and dropdown without using SQL in asp.net RRS feed

  • Question

  • User-508818466 posted

    Want to view the record locally from datatable to fields control without using sql queries.

    On click of view button in gridview all data from gridview will fetch on control field (eg. Textbox and dropdown), it  should view locally without using any SQL queries and procedure

    kindly help.

    Sunday, May 2, 2021 7:41 AM

All replies

  • User475983607 posted

    Want to view the record locally from datatable to fields control without using sql queries.

    On click of view button in gridview all data from gridview will fetch on control field (eg. Textbox and dropdown), it  should view locally without using any SQL queries and procedure

    kindly help.

    I'm not sure if I understand your question. 

    I think you want to enter GridView edit mode without quireing the database.  That's how the GridView typically works.  The GridView takes advantage of ViewState.  If your design is making a database call when the GridView enters edit mode, then that's logic you created.  You are not using the openly published standard GridView programming pattern(s).

    Is there anyway you can share sample code that reproduces the issue you are facing?  Explain the steps to reproduce the problem.  Explain the expected results and the actual results. 

    Sunday, May 2, 2021 11:59 AM
  • User-1716253493 posted

    I assume you have a gridview bound to a datatable

    You have LinkButton inside the gridview row

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            LinkButton lb = (LinkButton)sender;
            GridViewRow row =(GridViewRow)lb.NamingContainer;
            int rowidx = row.RowIndex;
        }

    Now, you have gridview row. You can find any text or control from the row.

    Or you can find data form gridview datatable based rowidx.

    If the grid allowpaging=true then gv.pageindex*gv.pagepagesize + rowidx

    Sunday, May 2, 2021 4:03 PM
  • User1535942433 posted

    Hi pvtt0050,

    According to your description,I don't understand your requirement clearly. I'm guessing are these:

    1.You have a gridview binding datatable.

    2.You could fetch data from gridview's row to textbox control which outside the gridview.

    If you need to do these,you could get the row index of the gridview.

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
      if (e.CommandName == "view")
      {
         // Retrieve the row index
         int index = Convert.ToInt32(e.CommandArgument);
    
         // Retrieve the row by its index
         GridViewRow row = this.GridView1.Rows[index];
    
        // Get the 1st cell value from the row
        string cellValue = r.Cells[0].Text;
      }

    Best regards,

    Yijing Sun

    Monday, May 3, 2021 6:39 AM