Web Forms :: How To Code - If It Is Not String In Vb
Dec 28, 2010at present i'm using like this
If Not IsNothing(ID) AndAlso Not ID = "" AndAlso Not CInt(ID) = 0 Then do something End If
i'd like to add, if it is not string. How?
at present i'm using like this
If Not IsNothing(ID) AndAlso Not ID = "" AndAlso Not CInt(ID) = 0 Then do something End If
i'd like to add, if it is not string. How?
I'm concatenating a string in codebehind to use in a sql select statement.
in aspx
<asp:Label ID="LabelHidden" runat="server" Visible="False"></asp:Label>
SelectCommand="SELECT * FROM [Data] WHERE [ActivityName] IN (@ActivityName) AND ([ID] = @ID)"
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList_Employees" Name="ID"
PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter ControlID="LabelHidden" Name="ActivityName"
Type="String" />
</SelectParameters>
in codebehind
foreach (ListItem li in ListBox_Activities.Items)
{
if (li.Selected)
{
queryBuilder += li + "', ";
}
queryBuilder = queryBuilder.Substring(0, queryBuilder.Length - 1);
LabelHidden.Text = queryBuilder;
When i run the code it comes up blank. I did a query trace and it seems to be running as
exec sp_executesql N'SELECT * FROM [Data] WHERE [ActivityName] IN (@ActivityName) AND ([ID] = @ID)',N'@EmployeeID int,@ActivityName nvarchar(50)',@EmployeeID=4,@ActivityName=N'Production Technical Support'', Tools Development'','
with exta "'s
How can i format the queryBuilder string correctly in my code?
I'm trying to to display the first 50 characters of text from a database field.
I thought I could do it something like this: <%# Eval("BodyTxt").ToString().Trim("50")) %> but it doesn't work.
I've also tried this: <%# Trim(Eval("BodyTxt")) %> although I never expected that to work.
how to remove string using c# code behind
my input
a="xxxx?folder=/~/QC/uploads"
my output
a=xxxx;
where xxxx =12,
=123
1234
I m trying to change the img src using the code behind.
A dinamic image that the final user can alter anytime and after this he can send that html content to some email adress.
My trouble is that when I change the image using the code behind the img src doesn't come with html content.
s is possible to nest connection string code as in the following?
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
ConnectionString="<%$ ConnectionStrings:'<%$ appSettings:myconnstr%>' %>">
</asp:SqlDataSource>
how can i search on my web page a specific string in source code ?
View 5 Repliescan i use this code add asp control on page str.append("textbox1.text") if no why?
View 2 RepliesI have to validate for whether the string is decimal/numeric in code behind in asp.net.
View 1 RepliesI have coded random string as below and i want to convert it to qr code , then send to email automatically...
Dim chars As String = "Test1"
Dim qr As String = ""
Dim r As New Random()
Dim i As Integer
For i = 1 To 5
qr += chars.Substring(r.Next(chars.Length), 1)
Next
I have a grid. I am building and populating it dynamically in C#. Below mentioned is my issue:
string s1 = "string1";
string s2 = "string2";
And then I have a header cell text which needs to be populated like this.
headercell.text = s1 + new string(' ', 20) + s2;
I am not able to get the extra 20 spaces between s1 and s2. It gives me just one space instead of 20 spaces.
I tried using headercell.text = s1 + s2.padleft(' ', 30); even then I am not able to get more than one space between strings s1 and s2.
[Code]....
If the table no data is displayed this error:
System.FormatException was unhandled by user code Message=Input string was not in a correct format.
[code]....
i have made a project that has an access database.
i have manage to connect and retrive data from the database at aspx and at code behind.
the problem is that i do not want to write the connection string at code behind again and again but to get it from the web.config as i am doing to the aspx pages.
this is what i do at aspx pages:
<add name="dataConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|data.mdb;Jet OLEDB:Database Password=data
@123" providerName="System.Data.OleDb"/>
[Code]....
I stored string in Variable then i assigned that value to TempData like this ,
String securityques = "Whats ur name";
TempData["SecQuesti"] = securityques;
When i use this code <%: TempData["DisplayName"]%> to display. it displays only
Whats , i want to display the full string...
Whats wrong in my coding ??
I have a Date Range in my asp page
<ks:DatePicker ID="txtMinDate" runat="server" Width="65px"></ks:DatePicker>
-<ks:DatePicker ID="txtMaxDate" runat="server" Width="65px"></ks:DatePicker>
Based on the date range selected and input in tthree more textboxes I populate the data grid. The code for the Data Grid is
grvLamination.DataSource = this.Controller.SearchLaminationMain(txtMinDate.Text,txtMaxDate.Text,txtJobNumber.Text,
txtJobName.Text, txtOperator.Text, System.Convert.ToInt32(txtShift.Text));
when i run this code it says Input String not in correct format, if i pass null values for all the parameters , I am using Linq to sql and If i execute the stored proc with null values in the database it works fine, it does not let me pass null values from the C sharp page.
<asp:CheckBox oncheckedchanged="chk1_CheckedChanged" ID=chk1 CssClass='<%# Eval("UserID") + "," + Eval("IsB") %>' runat="Server"/>
I got this check box on my page..if I need to assign these two values of CommandArgument in CssClass attribute ie <%# Eval("UserID") %> and <%# Eval("IsB") %> to two strings in my code behind..How do i do this?
protected void chk1_OnCheckChanged(object sender, EventArgs e)
{
string s1 = "Need the first value from Command argument here";
string s2 = "Need the second value from Command argument here";
}
how do i fetch those command argument values passed in CssClass attribute of checkbox?
ive an access database with a table, in this table there is only one data column and one counter column (id, pet) i want to draw random a record. Reading on the web i came with this SQL solution: "SELECT TOP 1 tab_pets.pet FROM tab_pets ORDER BY Rnd(id)" and it works perfectly.
The problem is while using this statement in my code behind (in a class) as it draw always the same record, hence generates the same random each time. I though that the access Rnd() function would be handled by the access driver and not by my application, how can i resolve this?
When to use GET and when POST. I want to hide my query string on code like :
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("~/Page1.aspx?mode=Create");
}
I don't want to show Create word in query string . What i have to do. And how to implement the Post/Redirect/Get pattern .Please send me code for this if possible.
I am developing a web application that will allow the customer to enter a personalized message, which will then be converted to HTML. Well, the problem is that I can not allow the insertion of Javascript code. So I need a method that filters the text, searching for and remove it. I think the regular expressions to solve my problem, but I'm having difficulty building.
View 1 Replieswhat code should i write in web.config for the connection string for DB connectivity woth ado.net component??
View 2 RepliesI want to create separate textbox for numbers and string using c# code. I should not use jquery or javascript.
Condition:
Numeric Textbox: It should not allow characters, special characters.
String Textbox: Should not allow numbers, Special characters.
How can I seek this sb string variable to get those variables:IMKB's value: 64882,72
how can I get it please show the seek idea
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
[code]...
I have a drop down box that is in the edit template of a formview. I want to be able to add a parrameter to the querystring when the drop down selected index is changed.
I tried
Request.QueryString.Add("tabindex", (sender as WebControl).TabIndex.ToString());
But I got an exception saying the collection is readonly.
Here is my markup
<icms_ref:ReferenceDropDownList ReferenceDataManagerProviderName="ROCSQLReferenceDataProvider"
ID="ddlEnquirerHearType" TabIndex="2" runat="server" ReferenceSetName="EnquiryHearType"
AutoPostBack="true" OnSelectedIndexChanged="EnquirerHearType_SelectedIndexChanged"
DataTextField="ShortName" DataValueField="ReferenceId" />
and here is my code behind.
protected void EnquirerHearType_SelectedIndexChanged(object sender, EventArgs e)
{
var pnlEnquiryHearTypeOther = fvEnquiryInformation.FindControl("pnlEnquiryHearTypeOther") as Panel;
pnlEnquiryHearTypeOther.Visible = DdlEnquirerHearType.SelectedValue == ((int)EnquiryHearType.Other).ToString();
ResetTextBox("txtEnquiryHearTypeOther", fvEnquiryInformation);
Request.QueryString.Add("tabindex", (sender as WebControl).TabIndex.ToString());
}
I am trying to get a new line when display the message. Whats wrong with this code?
Button l = (Button)e.Row.FindControl("btnDelete");
string textForMessage = @"<script language='javascript'> confirm('Are you sure you want to delete this record
test
test
test');</script>";
l.Attributes.Add("onclick", textForMessage + DataBinder.Eval(e.Row.DataItem, "Name") + ")");
"System.FormatException was unhandled by user code - Input string was not in a correct format"
This is driving me crazy! Can anyone see what the problem is?
[Code]....