0

I defined a function in asp.net and assigned this function to a Button click. In this function I have fetched a column from SQL server and assigned its values to a string variable. I want to see the value of this string.

Is there anyway in C# through which i can print the value of this string?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace Uma_Trial_2
{
    public partial class Trial1 : System.Web.UI.Page
    {
        public string final;
        protected string Page_Load(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
       // {
           // if (IsPostBack)
            //Initial is !IsPostBack
          //  {
               // BindData();
          //  }
       // }
        //protected string BindData(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {

            DropDownList ddlMul = new DropDownList();
            DataSet ds = new DataSet();
            SqlConnection conn = new SqlConnection(@"Data Source=xxxxxxxx;Initial Catalog=xxxxx;Persist Security Info=True;User ID=XXXXX;Password=XXXXXX@$$w0rd");
            conn.Open();
            string cmdstr = "select DISTINCT [Month_Abbr] from  [XXXXXXXXXXXX]";
            SqlDataAdapter adp = new SqlDataAdapter(cmdstr, conn);
            adp.Fill(ds);

            if (ds.Tables[0].Rows.Count > 0)
            {
                ddlMul = (DropDownList)e.Row.FindControl("DropDownMultiple1");

                if (ddlMul != null)
                {
                    ddlMul.DataSource = ds.Tables[0];
                    ddlMul.DataTextField = ds.Tables[0].Columns["Month_Abbr"].ColumnName.ToString();
                    ddlMul.DataValueField = ds.Tables[0].Columns["Month_Abbr"].ColumnName.ToString();
                    ddlMul.DataBind();
                }
            }

            List<String> Month_Abbr_list = new List<string>();

            foreach (System.Web.UI.WebControls.ListItem item in ddlMul.Items)
            {
                if (item.Selected)
                {
                    Month_Abbr_list.Add(item.Value);
                }

            }
            final = "(" + String.Join(",", Month_Abbr_list.ToArray()) + ")";  
            return final;


        }


    }
}
1
  • You can keep breakpoint at return final and check values there. Commented Dec 11, 2014 at 11:34

3 Answers 3

1

You can use

Response.Write(StringVariableHere);

or

Create asp label

<asp:Label ID="lblResult" runat="server" />

and

set text property of label

lblResult.Text = StringVariableHere;

or

You can use Visual Studio debugger to check variable values by putting breakpoint at desired location.

Sign up to request clarification or add additional context in comments.

5 Comments

I tried using the Response.write()...but it was showing a warning like "Unreachable Code detected".
@user3524441 Could you please edit your question and add your code. So I can have look into it.
I tried using Label control . It was executing, but could not see any label when i published the dashboard in the browser.
@user3524441 How you are calling this function " protected string Page_Load(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)" or where you are using this function
@rahul...I have a multiple Dropdown filter in my dashboard. So when i select multiple values in the filter and Click 'OK' button embedded in the filter, then that will trigger the page load. I want to Use the Selected values and pass on to WHERE IN clause in the data source query of the dashboard.
0

Could u show the String or a part of your Code?

there are some Methods to show your Value:

printf("\n yourString:");

Console.WriteLine(yourString);

Comments

0

You can simply add an asp Label control, set it as runat = server and access the control using name property to put string value in browser.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.