Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in Drop Down i have value type group like country state city etc and in grid view i have to bind values of these fields can anyone help ..plz
currently my code is like
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindMasterDataDropDown();
}
}

private void BindMasterDataDropDown()
{

//Read the ValueTypeGroupdata from valueTypeGroup table
List<valuetypegroup> valueTypeGroup = new List<valuetypegroup>();
valueTypeGroup = BLLMasterData.getAllValueTypeGroupData();

//Bind the data to drop down
ddlMasterData.DataSource = valueTypeGroup;
ddlMasterData.DataTextField = "ValueTypeGroupName";
ddlMasterData.DataValueField = "ValueTypeGroupID";
ddlMasterData.DataBind();
ddlMasterData.Items.Insert(0, new ListItem("--Please Select--", "0"));
}

protected void ddlMasterData_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlMasterData.SelectedValue == "0")
{
gvMasterData.Visible = false;
}
else
{
bindGridview();
}

}

private void bindGridview()
{
//Read the ValueType from valueType table
List<tendermanagement.model.valuetype> valueType = new List<tendermanagement.model.valuetype>();
valueType = BLLMasterData.getAllValueTypeData();

//Bind the data to drop down
gvMasterData.DataSource = valueType;
gvMasterData.DataBind();
}
}
Posted
Comments
pradiprenushe 2-Apr-13 2:09am    
Refer this
http://weblogs.asp.net/alaaalnajjar/archive/2009/11/16/group-options-in-dropdownlist.aspx
http://tutorials.cmsnsoftware.com/2011/12/how-to-use-option-group-with.html#0

1 solution

You have to do some minor changes in your code like
protected void ddlMasterData_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlMasterData.SelectedValue == "0")
{
gvMasterData.Visible = false;
}
else
{
bindGridview(Convert.ToInt32(ddlMasterData.SelectedValue));
}
 
}
 
private void bindGridview(int yourSelectedValue)
{
//select value from your database on the basis of the yourSelectedValue
List valueType = new List();
valueType = BLLMasterData.getAllValueTypeData();

//Bind the data to drop down
gvMasterData.DataSource = valueType;
gvMasterData.DataBind();
}
}
 
Share this answer
 
Comments
Vishal Pand3y 2-Apr-13 2:52am    
still not working is there some error in sp My sp is
ALTER PROCEDURE [dbo].[spGetAllMasterData]
AS
BEGIN
DECLARE @ValueTypeGroupID INT;
SET NOCOUNT ON;
SELECT [ValueTypeID]
,[ValueTypeGroupID]
,[ValueTypeName]
,[ParentValueTypeID]
,[CreatedBy]
,[ModifiedBy]
,[Enabled]
FROM [TenderKhabar].[dbo].[ValueType]
where
ValueTypeGroupID=@ValueTypeGroupID
END
Naz_Firdouse 2-Apr-13 3:18am    
you didn't set value for @ValueTypeGroupID.
check that once...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900