15,885,767 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Slacker89 (Top 11 by date)
Slacker89
10-May-13 3:18am
View
Bingo!!! I found the culprit :P I have to load event Monthdata at the end instead of first in ddprojectid_selectedindexchanged event. May be its taking null at first and then passing a value less than current selection to stored procedure. I found it using a label to display projectid selection before adapter fills in Monthdata().
i.e (In ddprojectid_SelectedIndexChanged event)I changed this
finally
{
Monthdata()
conn.Close();
}
Thank you very much for your valuable support. I have learnt something new today. Appreciate it Aarti :)
Slacker89
10-May-13 2:26am
View
That works with a small bug. For Ex: I select a Projectid for which BeginDate = 10/1/2012 and EndDate = 6/1/2013. It is showing the value of previous projectID calculated " MonthName" instead of showing for current selection. Once I select next projectid, previous rows MonthNames are pulled. Why is this happening? Stored Procedure works fine in SQL Server. Here is my code
private void Monthdata()
{
var str = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
var conn = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("Addmonthslist", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ProjectID", SqlDbType.VarChar).Value = ddprojectid.SelectedItem.Value;
cmd.Parameters.Add("@BeginDate", SqlDbType.VarChar).Value = tbbegin.Text;
cmd.Parameters.Add("@EndDate", SqlDbType.VarChar).Value = tbending.Text;
var adap = new SqlDataAdapter(cmd);
var ds = new DataSet();
adap.Fill(ds);
ddmonth.DataSource = ds.Tables[1];
ddmonth.DataTextField = "MonthName";
ddmonth.DataValueField = "MonthName";
ddmonth.DataBind();
}
protected void ddprojectid_SelectedIndexChanged(object sender, EventArgs e)
{
Monthdata(); // Populating above MonthData event on selection of ProjectID
var str = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string qry = "select CONVERT(VARCHAR(8), BeginDate, 1) AS BeginDate, CONVERT(VARCHAR(8), EndDate, 1) AS EndDate from tblProjects where ProjectID ='" + ddprojectid.SelectedItem.Value + "'";
SqlConnection conn = new SqlConnection(str);
SqlCommand cmd = new SqlCommand(qry, conn);
SqlDataReader sdr;
try
{
if (conn.State != ConnectionState.Open)
conn.Open();
sdr = cmd.ExecuteReader();
while (sdr.Read())
{
tbbegin.Text = sdr["BeginDate"].ToString();
tbending.Text = sdr["EndDate"].ToString();
}
}
catch (Exception ex)
{
lblError.Text = ex.ToString();
}
finally
{
conn.Close();
}
}
Slacker89
10-May-13 1:16am
View
My dumbness, Output of the SQL function wrote above i.e MonthName is not a column of the table. Table has only BeginDate, EndDate and ProjectID. That function takes these input and gives me output in the name of MonthName. How do I store "MonthName" result in a table? Is there any alternative for this problem? I am really sorry for confusing you.
Slacker89
9-May-13 19:13pm
View
I tried as you mentioned but I cannot get Displaymember as a property for dropdown. Here is my code, I used datatext and datavalue property( I know its wrong) since displaymember is not working. Please have a look and correct it. Appreciate your time and patience.
Error I got "DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'MonthName'."
private void Monthdata()
{
var str = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
var conn = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("Addmonthslist", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ProjectID", SqlDbType.VarChar).Value = ddprojectid.SelectedItem.Value;
cmd.Parameters.Add("@BeginDate", SqlDbType.VarChar).Value = ddbegin.Text;
cmd.Parameters.Add("@EndDate", SqlDbType.VarChar).Value = ddend.Text;
var adap = new SqlDataAdapter(cmd);
DataTable myDataTable = new DataTable();
adap.Fill(myDataTable);
ddmonth.DataSource = myDataTable;
ddmonth.DataTextField = "MonthName";
ddmonth.DataValueField = "MonthName";
ddmonth.DataBind();
}
Slacker89
9-May-13 3:38am
View
Thanks for your quick solution. It works like charm . You are awesome. How should I display this result in a dropdown. I tried using SQL dataadapter but it gave me an error since I am not declaring the output result anywhere. Please help me :(
Slacker89
29-Nov-12 12:30pm
View
Hie Manoj, Thanks for your solution. It works fine but still I am not able to sum using your functions. I have problem in sending client id to sum function. Please help me with this. Appreciate your time
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript" language="javascript">
function sumCalc() { // function to remove comma and then add to third textbo
var txt1 = document.getElementById('<%=tb1.ClientID %>').value.replace(/,/g, '');
var txt2 = document.getElementById('<%=tb2.ClientID %>').value.replace(/,/g, '');
var txt3 = document.getElementById('<%=tb3.ClientID %>').value = addCommas(parseFloat(txt1) + parseFloat(txt2));
}
function addCommas(clientID) {
var nStr = document.getElementById(clientID.id).value;
nStr += '';
x = nStr.split('.');
if (!x[0]) {
x[0] = "0";
}
x1 = x[0];
if (!x[1]) {
x[1] = "00";
}
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
document.getElementById(clientID.id).value = x1 + x2;
return true;
}
function removeCommas(clientID) {
var nStr = document.getElementById(clientID.id).value;
nStr = nStr.replace(/,/g, '');
document.getElementById(clientID.id).value = nStr;
$(clientID).select();
return true;
}
</script>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:TextBox ID="tb1" runat="server" onfocus="removeCommas(this)" OnBlur="addCommas(this)">
<asp:TextBox ID="tb2" runat="server" onfocus="removeCommas(this)" OnBlur="addCommas(this)">
<br />
<asp:Label ID="Label1" runat="server" Text="Result">
<br />
<asp:TextBox ID="tb3" runat="server" onfocus="javascript:sumCalc();">
<br />
<br />
<br />
Slacker89
28-Nov-12 20:36pm
View
Could you please elaborate it by pointing out changes that I need to make. I am newbie in java script.
Slacker89
25-Sep-12 23:45pm
View
Thanks for reply. Could you please elaborate your idea? I can use required field validator at client side but I don't want radio button list to be required field. I want it to take null value as another item such that users can change their selected value in edit item template . This link contains a similar problem but I am not sure of what datatype to actually use for radiobutton list so that I could find null values also.
http://forums.asp.net/t/1070081.aspx/1
Slacker89
15-Aug-12 18:44pm
View
hey thanks anywayz. I made it work by using default value and if condition in javascript function for that particular box to be equal to entered value else it takes default value (30%) and does the calculation for me. Thanks buddy.
Slacker89
15-Aug-12 18:01pm
View
Thanks a lot buddy . It helped a lot. Do you mind answering my small query? I want to have a textbox "LocalMatch Budget" that works based on percentage textbox multiplied to TextBox1. Percentage is another textbox with default value to 30% but it should allow user to change to his own % if user wants. If user dint change that percentage textbox then calculations for LocalMatch textbox should be done like (0.3*TextBox1)or if user changes percentage to some 50% then it should be (0.5*TextBox1). How should I proceed for this ? Appreciate your patience.
Note : Here TextBox1 is the obtained result for my first query
Slacker89
15-Aug-12 0:28am
View
Hey ..Thanks for your solution dude..It worked well. How can I make those textboxes not to accept negative values (like showing some alert)and also how to make that work for decimal values too..(like 12.9+11.1 =24.0). Thanks once again
Show More