Click here to Skip to main content
Rate this: bad
good
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 20:36pm
Comments
pradiprenushe at 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 at 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 at 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
0 DamithSL 265
1 CPallini 235
2 OriginalGriff 233
3 Maciej Los 195
4 George Jonsson 170
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2014
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