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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 18, 2013, 1:46 AM EDT
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);
}
}
}
Vishal GilbileRank #268 · 9.4K reputationPosted Mar 18, 2013, 12:38 AM EDT
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.
AbhiPriya M V63 reputationPosted Mar 18, 2013, 12:57 AM EDT
Vishal GilbileRank #268 · 9.4K reputationPosted Mar 18, 2013, 1:22 AM EDT
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 V63 reputationPosted Mar 18, 2013, 1:28 AM EDT
AbhiPriya M V63 reputationPosted Mar 18, 2013, 1:55 AM EDT