hi freinds,
Am binding values to gridview through itemtemplate of label. my question is
"how to displaying one of the column was drop down list while editing in the gridview.
and also how to bind values that dropdown list."
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 attend5days leftRegister
Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 12, 2010, 3:11 AM EST
you can do it by adding edititem template to your grid view see below example code:
Here is the code behind to bind the Dropdown list:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList cmbGender = (DropDownList)e.Row.FindControl("cmbNewGender");
if (cmbType != null)
{
cmbGender.DataSource = customer.FetchCustomerType();
cmbGender.DataBind();
cmbGender.SelectedValue = GridView1.DataKeys[e.Row.RowIndex].Values[1].ToString();
}
}
}
Please mark as answer if it helps you.
tekk62 reputationPosted Mar 12, 2010, 4:14 PM EST
Thanks for reply, i tried out your sent it code but did not getting output, only i getting data are binded to gridview but edit button showing header text only. Any i have to do settings in gridview or else. here i pasted it what i done and also i attached what i getting output. please check it and any wrong please tell me.
asp:GridView ID="GridView1" runat="server"
onrowdatabound="GridView1_RowDataBound" AutoGenerateColumns="False">
our "code behind code":
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
cmd.Connection = con;
string query = string.Format("select Genderfrom jobdetails");
cmd.CommandText = query;
SqlDataAdapter adap = new SqlDataAdapter();
adap.SelectCommand = cmd;
adap.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList cmbGender = (DropDownList)e.Row.FindControl("cmbNewGender");
if (cmbGender!= null)
{
cmbGender.DataSource = ds.Tables[0];
cmbGender.DataBind();
cmbGender.SelectedValue = GridView1.DataKeys[e.Row.RowIndex].Values[0].ToString();
}
}
Thanks,
comtekk
tekk62 reputationPosted Mar 12, 2010, 9:45 PM EST
Thanks for help, now am getting correctly.
Thanks,
Tekk
Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 14, 2010, 9:25 PM EDT
you should mark my answer if you get some help. It'll help other user to find the solution for same problems.
Best Regards
tekk62 reputationPosted Mar 25, 2010, 2:03 AM EDT
how to mark if answer is correct.