<asp:DropDownList ID="ddlsearchempgrid" AutoPostBack="true"
runat="server"><asp:ListItem Selected="True" Value="-Select-">-Select-</asp:ListItem>
</asp:DropDownList>
On .Cs page dropdown code
protected void binddropdownprj()
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Enigma"].ToString().Trim());
SqlDataAdapter da = new SqlDataAdapter("select * from cProject", con);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
ddlproject.DataSource = ds.Tables[0];
ddlproject.DataTextField = "createproject";
ddlproject.DataValueField = "ProjectId";
ddlproject.DataBind();
ddlproject.Items.Insert(0, new ListItem("-Select-"));
}
}
And On Page dropdown code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
binddropdownprj();
}
}
2.
Populating Dropdown Inside Gridview
On buttun code use onselectedindexchanged="" and then create this method on serverside.
if (e.Row.RowType == DataControlRowType.Header)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Enigma"].ToString().Trim());
SqlDataAdapter da = new SqlDataAdapter("Select * From Empdetail", con);
DataSet ds = new DataSet();
da.Fill(ds);
da.SelectCommand.CommandText = "select * from cProject ";
da.Fill(ds, "cproject");
if (ds.Tables[0].Rows.Count > 0)
{
DropDownList ddlgridfilter = new DropDownList();
ddlgridfilter = (DropDownList)e.Row.FindControl("ddlsearchempgrid");
ddlgridfilter.DataSource = ds.Tables[0];
ddlgridfilter.DataTextField = "EmpCode";
ddlgridfilter.DataValueField = "EmpCode";
ddlgridfilter.DataBind();
Dropdown list populating project currently not in correct format.
}
if (ds.Tables[1].Rows.Count > 0)
{
DropDownList ddlgrprj = new DropDownList();
ddlgrprj = (DropDownList)e.Row.FindControl("ddlproject");
ddlgrprj.DataSource = ds.Tables[1];
ddlgrprj.DataTextField = "createproject";
ddlgrprj.DataValueField = "ProjectId";
ddlgrprj.DataBind();
}
}
To Catch event when text changed of dropdown
protected void ddlprogress_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList dd=(DropDownList)viewtsk.HeaderRow.FindControl("ddlprogress");
dd1=dd.SelectedItem.Text;
string Eprg = ddlprogress.SelectedValue.ToString().Trim();
string Eprg = ((DropDownList)viewtsk.HeaderRow.FindControl("ddlprogress")).SelectedValue.ToString().Trim();
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Enigma"].ToString().Trim());
SqlDataAdapter dagrid = new SqlDataAdapter("select e.status,e.taskId,e.project,e.task,e.description,f.EmpCode from taskdetails e inner join Empdetail f on f.EmpCode = e.EmpCode where e.status='" + Eprg + "'", con);
DataSet dt = new DataSet();
dagrid.Fill(dt);
if (dt.Tables[0].Rows.Count > 0)
{
viewtsk.DataSource = dt;
viewtsk.DataBind();
}
}
No comments:
Post a Comment