Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I would like to display the data from database as per the selected value of drop down.

My code:
.aspx.cs
C#
protected void ddlDisplayName_SelectedIndexChanged(object sender, EventArgs e)
        {
            AdminActivityBL ObjAdminActivity = new AdminActivityBL();
            ObjAdminActivity.GetDisplayNames_Details();
            string SelectedValue = ddlDisplayName.SelectedItem.Value;
            
        }
Bussines layer:
C#
public DataSet GetDisplayNamesDetails()
        {
            AdminActivityDB objAdminActivityDB = new AdminActivityDB();
            return objAdminActivityDB.GetDisplayNamesDetails();
        }

Data access layer:
C#
public DataSet GetDisplayNamesDetails()
        {
            try
            {
                Database objDB = new SqlDatabase(ConfigurationHelper.ConnectionString);
                using (DbCommand objCMD = objDB.GetStoredProcCommand(Constants.USP_GET_DISPLAYNAMES_DETAILS))
                {
                    DataSet retDS = objDB.ExecuteDataSet(objCMD);
                    return retDS;
                }
            }
            catch (Exception ex)
            {
                //EventLog objLog = new EventLog();
                //objLog.LogError(ex);

                throw ex;
            }

        }

Is this something right?

:-)
Posted
Updated 30-Nov-12 20:56pm
v2
Comments
__TR__ 1-Dec-12 3:07am    
If you want to retrieve the data from database based on the selected value of dropdown, you need to pass the selected item's value/text of dropdown to database right? I don't see it in your code.
msweety 1-Dec-12 3:18am    
i want to pass by using selectedtext from the dropdown

protected void ddlDisplayName_SelectedIndexChanged(object sender, EventArgs e)
{
AdminActivityBL ObjAdminActivity = new AdminActivityBL();
ObjAdminActivity.GetDisplayNames_Details(DisplayName);
string SelectedValue = ddlDisplayName.SelectedItem.Value;

}
is this correct?
__TR__ 1-Dec-12 3:29am    
If you want to pass the selected text you need to use ListItem.Text Property[^].
string SelectedValue = ddlDisplayName.SelectedItem.Text;
Once you have the selected text value you need to pass it to your stored procedure so it returns the result based on the dropdown selection which is missing in your code.
msweety 1-Dec-12 3:45am    
i really didnot get...that..could you please explain with sample...code
msweety 1-Dec-12 6:31am    
i want to display the data in textboxes according to the selected value in dropdown list. need to select based on selected text. how to pass the selected text value to a stored proc?
pls help me


protected void ddlDisplayName_SelectedIndexChanged(object sender, EventArgs e)
{
AdminActivityBL ObjAdminActivity = new AdminActivityBL();
ObjAdminActivity.GetDisplayNames_Details();
string SelectedValue = ddlDisplayName.SelectedText.Value;

}
Bussines layer:


public DataSet GetDisplayNamesDetails()
{
AdminActivityDB objAdminActivityDB = new AdminActivityDB();
return objAdminActivityDB.GetDisplayNamesDetails();
}

Data access layer:

public DataSet GetDisplayNamesDetails(string SelectedValue)
{
try
{
Database objDB = new SqlDatabase(ConfigurationHelper.ConnectionString);
using (DbCommand objCMD = objDB.GetStoredProcCommand(Constants.USP_GET_DISPLAYNAMES_DETAILS))
{
DataSet retDS = objDB.ExecuteDataSet(objCMD);
return retDS;
}
}
catch (Exception ex)
{
//EventLog objLog = new EventLog();
//objLog.LogError(ex);

throw ex;
}

}

1 solution

hi please follow below links

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/042c1ea6-fd7c-41ed-9bb4-37245b86d797

http://msdn.microsoft.com/en-us/library/z72eefad(v=vs.90).aspx
 
Share this answer
 

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