-------------------------------------------------------------
############################################################
<asp:GridView ID="grdData" DataKeyNames="userid,categoryname">
protected void grdData_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList _ddlcategory = (DropDownList)e.Row.FindControl("ddlcategory");
if (_ddlcategory != null)
{
_ddlcategory.DataSource = GetCategory();
_ddlcategory.DataTextField = "categoryname";
_ddlcategory.DataValueField = "categoryname";
_ddlcategory.DataBind();
_ddlcategory.SelectedItem.Text = grdData.DataKeys[e.Row.RowIndex].Values[1].ToString();
}
}
}
public DataTable GetCategory()
{
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["conPractice"].ToString();
SqlDataAdapter adp = new SqlDataAdapter("GetCategory", con);
adp.Fill(dt);
return dt;
}
############################################
0 comments:
Post a Comment