Click here to Skip to main content
15,878,748 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have a web form.Which consists 3 fields. From date, to Date, Seller Name. on click of submit button, data of all 3 fields should be displayed in RDLC report.. rightnow only the id of dropdown is displaying instaed of the name.. I am using a master called userinfo to get the details of seller.
I used
ddlSeller.SelectedItem.Text
.Even this doesn't work.
Kindly help

What I have tried:

i have used this..
dropdown.selecteditem.text
Posted
Updated 27-Jun-17 21:35pm

1 solution

It depends on what you want to fetch from the DropDown List...

This is to get the Text of the DropDown List:

C#
string dropDownText = DropList.SelectedItem.Text.ToString();


This is to get the Value of the DropDown List:

C#
string dropDownValue = DropList.SelectedValue.ToString();
 
Share this answer
 
Comments
Member 11933161 28-Jun-17 4:30am    
Thanks for the reply.. I will tell my issue in deep.
I have written the following code in Reportviewer.aspx.cs page:
ViewState["FROM"] = Request["FROM"].ToString();
ViewState["TO"] = GetString(Request["TO"].ToString());

ViewState["SELLER"] =Request["SELLER"].ToString();

string fDate = ViewState["FROM"].ToString();
string toDate = ViewState["TO"].ToString();

int seller = int.Parse(ViewState["SELLER"].ToString()); //i am getting error here as "Input string was not in a correct format.".//

DateTime from = Convert.ToDateTime(fDate);
fDate = from.ToString("yyyy-MM-dd");

DateTime to = Convert.ToDateTime(toDate);
toDate = to.ToString("yyyy-MM-dd");

string lstrConn = System.Configuration.ConfigurationManager.ConnectionStrings["SQLConnString"].ToString();


SqlConnection conn = new SqlConnection(lstrConn);
conn.Open();
string sql = "Select * FROM V_DemoRep ";

//if (seller > 0)
// sql = sql + " sellername " + seller;

SqlDataAdapter ad = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
ad.Fill(ds);

//ReportViewer2.ProcessingMode = ProcessingMode.Local;
////set path of the Local report
//ReportViewer2.LocalReport.ReportPath = Server.MapPath("~/rptVOrder.rdlc");

ReportDataSource rds = new ReportDataSource("DataSet1", ds.Tables[0]);
ReportViewer1.Width = Unit.Pixel(1200);
ReportViewer1.Height = Unit.Pixel(700);


ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(rds);
ReportViewer1.LocalReport.Refresh();

& i have written code in tripreport.aspx.cs page:
private void pBindDDL()
{
DataTable dtFTLInfo = BuyerSellerTranAccept.GetBySeller(myUserInfo.Company.SlNo);

ddlSeller.Items.Clear();
ddlSeller.DataSource = dtFTLInfo;
ddlSeller.DataValueField = "slno";
ddlSeller.DataTextField = "Name";

ddlSeller.DataBind();
ddlSeller.Items.Insert(0, new ListItem("--Select--", "0"));
}
protected void Page_ResetButton(object sender, EventArgs e)
{
pClearControl();
}
private void pClearControl()
{

txtFromDate.Text = "";
txtToDate.Text = "";

}
protected void Page_SubmitButton(object sender, EventArgs e)
{


pShowReports();
// ViewReport(reportName, sSelectionFormula, sParameter, sFormula);
}
private void pShowReports()
{
if (myUserInfo == null) myUserInfo = (Model.Masters.SubscriberInfo)ViewState[USER_KEY];

StringBuilder sb = new StringBuilder();
sb.Append("");

// sb.Append("window.open('../Registers.aspx')");
sb.Append("window.open('TripStatusViewer.aspx?FROM=" + txtFromDate.Text + "&TO=" + txtToDate.Text + "&SELLER=" + ddlSeller.SelectedItem.Text.ToString() +"')");
// sb.Append("window.open('../Registers.aspx?ID=" + reportName + "')");
//+ "&SELFORMULA=" + sSelectionFormula + "&PARAMETER=" + sParameter + "&FORMULA=" + sFormula + "')");
sb.Append("");

if (!Page.ClientScript.IsClientScriptBlockRegistered("report"))
ScriptManager.RegisterStartupScript(btnSubmit, this.GetType(), "report", sb.ToString(), false);


}

}
}
Prifti Constantine 28-Jun-17 5:09am    
I cannot understand the problem in this section of the code and what does it have to do with the drop down list that you mentioned above. Also i would reccomend using session object to store the date you want instead of ViewState. The only obvious error that i see here is that the parsing of ViewState["Seller"] fails to compile according your mentions.Can i have some clarification on what exactly does Request["Seller"] returns?
Prifti Constantine 28-Jun-17 5:16am    
It came to me that Seller is apparently the value that you want to retrieve from a control in the aspx file and populate the Seller value in the stringbuilder with it. One problem would be that the value you get in the ViewState["Seller"] might be null or might not contail numerical or grammatical values.
Member 11933161 28-Jun-17 6:21am    
Actually, there is a master called company. & seller is derived from that company master. I have a web page with seller drop down.. When i click that drop-down i can see the names of the seller companies. But when i submit, i can see only the SlNo of the sellers in the report.. I want to display the names of the sellers in the report.
Prifti Constantine 29-Jun-17 3:32am    
My answer is still to user the
string dropDownText = DropList.SelectedItem.Text.ToString();

If the value you want to retrieve is inside the Text attribute of the dropDownList then the above example should work fine..
If the value you want to retrieve is inside the Value attribute of the dropDownList then
this is what you should use:
string dropDownValue = DropList.SelectedValue.ToString();

In each case you have to pay attention to which attribute of the dropDownList you have assigned the Value you want to get.

What i do not understand in your comment is what exactly is SINo of the sellers

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