Click here to Skip to main content
12,406,124 members (41,709 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 = new List();
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 valueType = new List();
valueType = BLLMasterData.getAllValueTypeData();

//Bind the data to drop down
gvMasterData.DataSource = valueType;
gvMasterData.DataBind();
}
}
Posted 1-Apr-13 19:36pm
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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();
}
}
  Permalink  
Comments
emvishal.pandey 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160726.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100