Abhimanyu K Vatsa

Abhimanyu K Vatsa

  • NA
  • 40.4k
  • 21.4m

data in GridView

Jun 11 2010 5:53 AM
Hello I want to display the retried data in GridView1. How to processed here

protected void Button1_Click(object sender, EventArgs e)
    {
        //data soure control that works with sql database
        SqlDataSource sds = new SqlDataSource();
        //get connection string from application's web.config file
        sds.ConnectionString = ConfigurationManager.ConnectionStrings["myDbConnectionString1"].ToString();
        //create parameters with specified name and values
        sds.SelectParameters.Add("roll", TypeCode.String, this.TextBox1.Text);
        //set the sql string to retrive data from the database
        sds.SelectCommand = "SELECT * FROM [myTb] WHERE [roll]=@roll";
        //retrive data
        DataView dv = (DataView)sds.Select(DataSourceSelectArguments.Empty);
        if (dv.Count == 0)
        {
            this.Label1.Text = "No Data Found";
            return;
        }
        else
        {
            this.GridView1.DataSource =
dv.Select();
        }
    }





Please look at the red colored text and reply me what I have to write there to receive the data in GridView1.


Help me !

Answers (2)