how to display the selected row value of an gridview in dropdowlist in asp.net c#???
thank u!!!
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Mar 18, 2013, 5:46 AM
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Select_row_value_gridview_dropdown
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
}
}
void bindgrid()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from student";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "student");
GridView1.DataSource = ds;
GridView1.DataMember = "student";
GridView1.DataBind();
con.Close();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
ddl_id.Items.Clear();
ddl_name.Items.Clear();
ddl_address.Items.Clear();
ddl_marks.Items.Clear();
ddl_year.Items.Clear();
ddl_id.Items.Add(GridView1.SelectedRow.Cells[1].Text);
ddl_name.Items.Add(GridView1.SelectedRow.Cells[2].Text);
ddl_address.Items.Add(GridView1.SelectedRow.Cells[3].Text);
ddl_marks.Items.Add(GridView1.SelectedRow.Cells[4].Text);
ddl_year.Items.Add(GridView1.SelectedRow.Cells[5].Text);
}
}
}
AbhiPriya M VPosted Mar 18, 2013, 5:55 AM
AbhiPriya M VPosted Mar 18, 2013, 5:28 AM
Vishal GilbilePosted Mar 18, 2013, 5:22 AM
In that case you need to make use of GridView SelectedIndexChanging event of your gridview control. Below is the code for the same.
In the above code I'm just displaying the values. you can do whatever is your scenario.
Hope that solves your problem.
With Regards,
Vishal Gilbile.
AbhiPriya M VPosted Mar 18, 2013, 4:57 AM
Vishal GilbilePosted Mar 18, 2013, 4:38 AM
For selection which control you are using I mean whether you are using a Checkbox or a link button and also whether your gridview is making use of Template Field or not.
With Regards,
Vishal Gilbile.