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.
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.
tekkPosted Mar 25, 2010, 6:03 AM
how to mark if answer is correct.
Amit ChoudharyPosted Mar 15, 2010, 1:25 AM
you should mark my answer if you get some help. It'll help other user to find the solution for same problems.
Best Regards
tekkPosted Mar 13, 2010, 2:45 AM
Thanks for help, now am getting correctly.
Thanks,
Tekk
tekkPosted Mar 12, 2010, 9:14 PM
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
Amit ChoudharyPosted Mar 12, 2010, 8:11 AM
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.