You must Sign In to post a response.
  • Category: [Competition Entries]

    About data display in Gridview.


    Are you looking for information on gridview controls? Want to know how to display data in Gridview? Read this thread to learn more about getting data from database and showing in the gridview by pressing enter key.



    Sir I want to code for c# in which I can submit the text in the first column of Datagridview and then press enter key so how it will display the data from database rest of the record into my datagridview columns
    Plz help me
  • #708190
    Hi,
    Design Gridview with template controls
    Then create an empty gridview by binding with dummy tables
    Handle in Row command event of the gridview,retrieve the data from the database which is matching the value entered in textbox.
    Hope it will work.

    Have a good Day

  • #708220
    thanks mem
    But to understand my actual requiremnt u can see the attatched picin the datagrid i want to enter the text into the first column and want to display the rest data from database in the datagrid columns like purchase price, sale price , etc on behalf of text entered in particular

    Delete Attachment

  • #708259
    Hai TarunKumar,

    You can achieve this by using Datareader.
    Just Create a function that read corresponding Details from the database.
    Like this..


    public void get_product_inform(string particular, int index)
    {
    SqlConnection con=new SqlConnection("Your connection string");
    SqlCommand cmd = new SqlCommand("select price,saleprice,Quantity,DofPurchase from tblProduct where particular='" + particular + "'", con);
    SqlDataReader dr;
    try
    {
    con.Open();
    dr = cmd.ExecuteReader();
    if (dr.Read())
    {
    datagrid_Purchase.Rows[index].Cells[1].Value = dr[0].ToString();
    datagrid_Purchase.Rows[index].Cells[2].Value = dr[1].ToString();
    datagrid_Purchase.Rows[index].Cells[3].Value = dr[2].ToString();
    datagrid_Purchase.Rows[index].Cells[4].Value = dr[3].ToString();

    }
    else
    {
    datagrid_Purchase.Rows[index].Cells[1].Value = "";
    datagrid_Purchase.Rows[index].Cells[2].Value = "";
    datagrid_Purchase.Rows[index].Cells[3].Value= "";
    datagrid_Purchase.Rows[index].Cells[4].Value= "";
    }

    dr.Close();


    }
    catch(Exception ex)
    {
    MessageBox.Show("Failed to get product infomation"+ex.ToString());
    }
    finally
    {
    con.Close();
    }
    }


    Now call the function in the datagridview cellEndEdit event like


    private void datagrid_Purchase_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {

    if(e.ColumnIndex==0)
    {
    get_product_inform(datagrid_Purchase.Rows[e.RowIndex].Cells[0].Value.ToString(),e.RowIndex);
    }


    }



    Thats it..Now after enter your particular you can get the rest data from database in datagridview columns..


    Try this..


    R.SURESH,
    Dotnet Developer.


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.