Saturday, March 31, 2012
submitting a PDF form
I have been trying to figure this out for quite some time and I am getting a bit frustrated, any help would be greatly appreciated.
Thanks.Code would be useful. What does the command look like that's attempting to write to the db? Is the information supplied to gain access to the db correct? Are the table/field names correct? Is your syntax correct?
The reason that I didnt bother posting any code is because I am getting stuck before the point that I try to put the info into the db. I cant even retrieve the form variables
Request.form("name of filed from pdf form")
this value gives me nothing.
My question is if there is something that I am supposed to be doing in the PDF form that should make this work.
thanks.
http://www.tgreer.com/pdfSubmit.html
submitting form values
Hi all, (fyi, I know ASP well, .NET is new)
ok, submitting a form. Few things:
1. the form is a custom collage of textboxes, no formview, no detailsview, just textboxes, dropdownlists, and datavalidators.
2. The form get populated via querystring'd 'UserID' as so:---------------
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim strSQL As String
Dim myDataReader As OleDbDataReader
Session.Item("CurrentUserIDtoEdit") = Request.QueryString("UserID")
strSQL = "SELECT * FROM Users " _
& "WHERE uniqueid='" & Session.Item("CurrentUserIDtoEdit") & "'"
myConnection = New OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("strConn"))
myCommand = New OleDbCommand(strSQL, myConnection)
myConnection.Open()
myDataReader = myCommand.ExecuteReader()
Do While (myDataReader.Read())
TextboxFirstName.Text = Convert.ToString(myDataReader("FirstName"))
TextboxLastName.Text = Convert.ToString(myDataReader("LastName"))
TextboxAddress1.Text = Convert.ToString(myDataReader("Address1"))
TextboxAddress2.Text = Convert.ToString(myDataReader("Address2"))
TextboxCity.Text = Convert.ToString(myDataReader("City"))
DropDownState.SelectedValue = Convert.ToString(myDataReader("State"))
TextBoxZipCode.Text = Convert.ToString(myDataReader("Zip"))
TextBoxPhone.Text = Convert.ToString(myDataReader("Phone"))
TextBoxEmail.Text = Convert.ToString(myDataReader("emailaddress"))
TextboxUsername.Text = Convert.ToString(myDataReader("Username"))
TextboxPassword.Text = Convert.ToString(myDataReader("Password"))
DropDownListPermissionLevel.SelectedValue = myDataReader("PermissionLevel")
CheckBoxDeleted.Checked = Convert.ToBoolean(myDataReader("Deleted"))
Loop
myDataReader.Close()
myConnection.Close()
--------------THIS WORKS GREAT
Question is, this page is a 'Modify User' page. What I want is it to populate with current 'User' data from the DB (that's working fine. as above)
AND, when resubmitted, update the DB with the new data from the form, show a 'success label' of some sort with a minor delay, and response.redirect to 'Menu.aspx'
isPostBack is an option, yes...but how to integrate that conditional coding with a SQLDataObject? or do I hard code the update like the above code...and how?
(I have the Stored Procedure as follows)----------
CREATE PROCEDURE dbo.UpdateUser
(
@dotnet.itags.org.UniqueID int,
@dotnet.itags.org.FirstName nvarchar(50),
@dotnet.itags.org.LastName nvarchar(50),
@dotnet.itags.org.Address1 nvarchar(100),
@dotnet.itags.org.Address2 nvarchar(100),
@dotnet.itags.org.City char(100),
@dotnet.itags.org.State char(2),
@dotnet.itags.org.Zip char(5),
@dotnet.itags.org.Phone char(10),
@dotnet.itags.org.emailaddress nvarchar(100),
@dotnet.itags.org.Username nvarchar(50),
@dotnet.itags.org.Password nvarchar(50),
@dotnet.itags.org.PermissionLevel char(1),
@dotnet.itags.org.Deleted bit,
@dotnet.itags.org.SystemUserID int
)
AS
SET NOCOUNT OFF;
UPDATE Users
SET
FirstName = @dotnet.itags.org.FirstName,
LastName = @dotnet.itags.org.LastName,
Address1 = @dotnet.itags.org.Address1,
Address2 = @dotnet.itags.org.Address2,
City = @dotnet.itags.org.City,
State = @dotnet.itags.org.State,
Zip = @dotnet.itags.org.Zip,
Phone = @dotnet.itags.org.Phone,
emailaddress = @dotnet.itags.org.emailaddress,
username = @dotnet.itags.org.Username,
[Password] = @dotnet.itags.org.Password,
PermissionLevel = @dotnet.itags.org.PermissionLevel,
Deleted = @dotnet.itags.org.Deleted,
LastModifiedBy = @dotnet.itags.org.SystemUserID,
LastModifiedDate = CURRENT_TIMESTAMP
where Uniqueid = @dotnet.itags.org.UniqueID
GO
-----------
Do I somehow, link the SQLDataobject with the 'onclick' event of the 'submit' button?
NOTE: I figured out that the SQLDataobject has an updatecommandtype and an updatequery property panel where I set the params for the SP correctly to the form vars and session.items so it's ready to go...
---
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ProductionConnectionString %>"
InsertCommand="InsertUser" InsertCommandType="StoredProcedure" SelectCommand="GetUser"
SelectCommandType="StoredProcedure" UpdateCommand="UpdateUser" UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:SessionParameter Name="UniqueID" SessionField="CurrentUserIDtoEdit" Type="Int32" />
<asp:ControlParameter ControlID="TextboxFirstName" Name="FirstName" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="TextboxLastName" Name="LastName" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="TextboxAddress1" Name="Address1" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="TextboxAddress2" Name="Address2" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="TextboxCity" Name="City" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="DropDownState" Name="State" PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="TextBoxZipCode" Name="Zip" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="TextBoxPhone" Name="Phone" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="TextBoxEmail" Name="emailaddress" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="TextboxUsername" Name="Username" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="TextboxPassword" Name="Password" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="DropDownListPermissionLevel" Name="PermissionLevel"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="CheckBoxDeleted" Name="Deleted" PropertyName="Checked"
Type="Boolean" />
<asp:SessionParameter Name="SystemUserID" SessionField="UserID" Type="Int32" />
<asp:Parameter Direction="ReturnValue" Name="RETURN_VALUE" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:QueryStringParameter DefaultValue="" Name="UserID" QueryStringField="UserID"
Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Address1" Type="String" />
<asp:Parameter Name="Address2" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="State" Type="String" />
<asp:Parameter Name="Zip" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Fax" Type="String" />
<asp:Parameter Name="emailaddress" Type="String" />
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="Password" Type="String" />
<asp:Parameter Name="PermissionLevel" Type="String" />
<asp:Parameter Name="CurrentUserID" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<table>
<tr>
<td colspan="3" align="left"><asp:Label ID="Label1" runat="server" Text="Modify User" Font-Size="Large"></asp:Label></td>
</tr>
<tr>
<td style="height: 24px">First Name</td>
<td style="height: 24px"><asp:TextBox ID="TextboxFirstName" runat="server"></asp:TextBox></td>
<td style="height: 24px"><asp:RequiredFieldValidator ID="RequiredFieldValidatorFirstName" runat="server" ControlToValidate="TextboxFirstName"
ErrorMessage="First Name Required"></asp:RequiredFieldValidator> </td>
</tr>
<tr>
<td>Last Name</td>
<td><asp:TextBox ID="TextboxLastName" runat="server"></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidatorLastName" runat="server"
ControlToValidate="TextboxLastName" ErrorMessage="Last Name Required"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Address 1</td>
<td><asp:TextBox ID="TextboxAddress1" runat="server"></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidatorAddress1" runat="server"
ControlToValidate="TextboxAddress1" ErrorMessage="Address Required"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Address 2</td>
<td><asp:TextBox ID="TextboxAddress2" runat="server"></asp:TextBox></td>
<td></td>
</tr>
<tr>
<td>City</td>
<td><asp:TextBox ID="TextboxCity" runat="server"></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldCity" runat="server"
ControlToValidate="TextboxCity" ErrorMessage="City Required"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>State</td>
<td><asp:DropDownList id="DropDownState" runat="server"
<asp:ListItem Value="AL">Alabama</asp:ListItem
<asp:ListItem Value="AK">Alaska</asp:ListItem
<asp:ListItem Value="AZ">Arizona</asp:ListItem
<asp:ListItem Value="AR">Arkansas</asp:ListItem
<asp:ListItem Value="CA">California</asp:ListItem
<asp:ListItem Value="CO">Colorado</asp:ListItem
<asp:ListItem Value="CT">Connecticut</asp:ListItem
<asp:ListItem Value="DC">District of Columbia</asp:ListItem
<asp:ListItem Value="DE">Delaware</asp:ListItem
<asp:ListItem Value="FL">Florida</asp:ListItem
<asp:ListItem Value="GA">Georgia</asp:ListItem
<asp:ListItem Value="HI">Hawaii</asp:ListItem
<asp:ListItem Value="ID">Idaho</asp:ListItem
<asp:ListItem Value="IL">Illinois</asp:ListItem
<asp:ListItem Value="IN">Indiana</asp:ListItem
<asp:ListItem Value="IA">Iowa</asp:ListItem
<asp:ListItem Value="KS">Kansas</asp:ListItem
<asp:ListItem Value="KY">Kentucky</asp:ListItem
<asp:ListItem Value="LA">Louisiana</asp:ListItem
<asp:ListItem Value="ME">Maine</asp:ListItem
<asp:ListItem Value="MD">Maryland</asp:ListItem
<asp:ListItem Value="MA">Massachusetts</asp:ListItem
<asp:ListItem Value="MI">Michigan</asp:ListItem
<asp:ListItem Value="MN">Minnesota</asp:ListItem
<asp:ListItem Value="MS">Mississippi</asp:ListItem
<asp:ListItem Value="MO">Missouri</asp:ListItem
<asp:ListItem Value="MT">Montana</asp:ListItem
<asp:ListItem Value="NE">Nebraska</asp:ListItem
<asp:ListItem Value="NV">Nevada</asp:ListItem
<asp:ListItem Value="NH">New Hampshire</asp:ListItem
<asp:ListItem Value="NJ">New Jersey</asp:ListItem
<asp:ListItem Value="NM">New Mexico</asp:ListItem
<asp:ListItem Value="NY">New York</asp:ListItem
<asp:ListItem Value="NC">North Carolina</asp:ListItem
<asp:ListItem Value="ND">North Dakota</asp:ListItem
<asp:ListItem Value="OH">Ohio</asp:ListItem
<asp:ListItem Value="OK">Oklahoma</asp:ListItem
<asp:ListItem Value="OR">Oregon</asp:ListItem
<asp:ListItem Value="PA">Pennsylvania</asp:ListItem
<asp:ListItem Value="RI">Rhode Island</asp:ListItem
<asp:ListItem Value="SC">South Carolina</asp:ListItem
<asp:ListItem Value="SD">South Dakota</asp:ListItem
<asp:ListItem Value="TN">Tennessee</asp:ListItem
<asp:ListItem Value="TX">Texas</asp:ListItem
<asp:ListItem Value="UT">Utah</asp:ListItem
<asp:ListItem Value="VT">Vermont</asp:ListItem
<asp:ListItem Value="VA">Virginia</asp:ListItem
<asp:ListItem Value="WA">Washington</asp:ListItem
<asp:ListItem Value="WV">West Virginia</asp:ListItem
<asp:ListItem Value="WI">Wisconsin</asp:ListItem
<asp:ListItem Value="WY">Wyoming</asp:ListItem
</asp:DropDownList>
</td>
<td></td>
</tr>
<tr>
<td>Zip Code</td>
<td><asp:TextBox ID="TextBoxZipCode" runat="server"></asp:TextBox></td>
<td><asp:RegularExpressionValidator id="RegularExpressionValidatorZipCode" runat="server" ErrorMessage="Zip format (12345-1234) last four optional" ControlToValidate="TextBoxZipCode" ValidationExpression="\d{5}(-\d{4})?"></asp:RegularExpressionValidator></td>
</tr>
<tr>
<td>Phone</td>
<td><asp:TextBox ID="TextBoxPhone" runat="server"></asp:TextBox></td>
<td><asp:RegularExpressionValidator ID="RegularExpressionValidatorPhone" runat="server" ErrorMessage="Phone Format (1234567890)" ControlToValidate="TextBoxPhone" ValidationExpression="((\(\d{3}\) ?)|(\d{3}))?\d{3}\d{4}"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>Email</td>
<td><asp:TextBox ID="TextBoxEmail" runat="server"></asp:TextBox></td>
<td><asp:RegularExpressionValidator id="RegularExpressionValidatorEmail" runat="server" ErrorMessage="Email format (a@dotnet.itags.org.a.com)" ControlToValidate="TextBoxEmail" ValidationExpression="\w+([-+.']\w+)*@dotnet.itags.org.\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></td>
</tr>
<tr>
<td>Username</td>
<td><asp:TextBox ID="TextboxUsername" runat="server"></asp:TextBox></td>
<td><asp:RegularExpressionValidator ID="RegularExpressionValidatorUsername" runat="server" ErrorMessage="Username must be 4 chars long and start with a letter." ControlToValidate="TextboxUsername" ValidationExpression="^[A-Za-z]\w{3,}$"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>Password</td>
<td><asp:TextBox ID="TextboxPassword" runat="server"></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidatorPassword" runat="server"
ControlToValidate="TextboxPassword" ErrorMessage="Password Required"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Permission Level</td>
<td><asp:DropDownList ID="DropDownListPermissionLevel" runat="server">
<asp:ListItem Selected="True">Select One...</asp:ListItem>
<asp:ListItem Value="1">Admin</asp:ListItem>
<asp:ListItem Value="2">Manager</asp:ListItem>
</asp:DropDownList></td>
<td></td>
</tr>
<tr>
<td>Deleted</td>
<td><asp:CheckBox ID="CheckBoxDeleted" runat="server" /></td>
<td></td>
</tr>
<tr><td colspan="3">
<asp:ValidationSummary ID="ValidationSummaryAddUser" runat="server" />
</td></tr>
<tr>
<td style="height: 24px"><asp:Button ID="ResetButton" runat="server" Text="Reset" /></td>
<td style="height: 24px"><asp:Button ID="SubmitButton" runat="server" Text="Submit" /></td>
<td style="height: 24px"></td>
</tr>
</table>
</div>
</asp:Content>
---
just how to make the SQLDataobject and submit button onclick to like each other?
Thanks again all.
Hi,
Based on your description, I understand that you have created a SqlDataSource control on a table, and have created Select, Insert and Update command on it. If there is any misunderstanding, please feel free to let me know.
Usually, the Select command is fired by calling DataBind method on the controls. When binding, the method is called and the returned DataReader or DataSet is automatically bind to the controls.
For Update and Insert method, you will have to call the Update() or Insert() manually. In your case, call SqlDataSource1.Update() in the Submit button. If it's a newly added record, call SqlDataSource1.Insert().
If you need to know if the record has been added, you can use IF EXISTS statement to check existence in database.
IF EXISTS (SELECT * FROM t1 WHERE id = @.id)
BEGIN
--Call Update
END
ELSE
BEGIN
--Call Insert
END
Hope this helps.
Thank you for your reply.
Since my post, I've been non-stop .NET-in-ating and I've learned much. I wound up doing the following
Protected Sub SubmitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitButton.Click
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim intUserCount As Integer
Dim strSQL As String
strSQL = "Insert into Users " _
& "(FirstName, LastName, Username, Password, Permissionlevel)" _
& "VALUES ('" & Trim(Replace(TextboxFirstName.Text, "'", "''")) & "','" _
& Trim(Replace(TextboxLastName.Text, "'", "''")) & "','" _
& Trim(Replace(TextboxUsername.Text, "'", "''")) & "','" _
& Trim(Replace(TextboxPassword.Text, "'", "''")) & "','" _
& Trim(Replace(DropDownListPermissionLevel.SelectedItem.Value, "'", "''")) & "')"
myConnection = New OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("strConn"))
myCommand = New OleDbCommand(strSQL, myConnection)
myConnection.Open()
intUserCount = myCommand.ExecuteScalar()
myConnection.Close()
End Sub
But now, I've learned how to modify the 'templates' for a gridview/detailsview combo. I'm an old ASP guy, as I've said. So, messing with this has been good exercise to understand what's going on.
Since this posting, I've changed my whole view of how a 'control panel' could/needs to be laid out. This new .NET stuff is changing my way of 'organizing control panel' type portions of web sites.
As an exercise I'm converting www.beaudamore.com/ProductionManagement form old ASP into ASP.NET using VB as the base code. The whole way the 'Menu' is laid out is going to change in respect to this whole new programming style. I'm envisioning it different, simpler, but equally powerful. I will post more, perhaps my view form old ASP will help other 'old timers' as well. I think I took too long to make the change.
Thanks again.
Submitting seperate values from a checkbox list?
does anyone have time to explain how to submit seperate values from my checkbox list?
I would be muchly appreciative.
so far I have the first boxes value returning, I realise it has to go in the if/foreach loop to make a value for each one but when I put my sql command in there it can't be recognized...
please help!!
-Matt
You can store the variables's values in an array, and then submit it.SqlCommand cmdInterest;
cmdInterest = new SqlCommand( "Insert tbl_interests ( interestID ) Values (@dotnet.itags.org.interestID) ", conform );
//check box item testing
foreach (ListItem itmInterest in chkl_interests.Items)
{if (itmInterest.Selected){
//now I have no idea what to put here??
}
}cmdInterest.Parameters.Add( "@dotnet.itags.org.interestID", chkl_interests.SelectedItem.Value );
conform.Open();
cmdInsert.ExecuteNonQuery();
cmdInterest.ExecuteNonQuery();conform.Close();
string[] names = new string[5];
int i = new int();
for each (ListItem itmInterest in chkl_interests.Items)
{
names[i] = chkl_interests.Items.tostring();
i++;
}
then in the pre-render event, just store the value before you submit it.
viewstate("names") = names;
to pass its value to the client do this:
response.write("<script language=""Javascript""> ")
response.write("var array[5]; ")
response.write("array = " + names + "; ")
response.write("</script>")
I dont know if this will help you, but i dont really know what do you want.
Wednesday, March 28, 2012
substitute data from database into web form
Hello.
Newbie here, I have a field in a database called status with the values "I" or "A". I need to display "Inactive" or "Active" in a gridview or formview web page. How do I substitute these values.
Thanks in advance.
Is this data being displayed in a datalist / datagrid? You can either create a temp table in your sql or modify your code. If you post your code I can show you how, otherwise you can do something like this in your sql:
create table #temp(
activeInactiveField1 char(5)
, activeInactiveField2 char(10)
-- , your other fields here
)
Insert into #Temp(
-- all fields from your existing sql
from all your existing tables
update #temp
set activeInactiveField2 = 'Active'
where activeInactiveField1 = 'A'
update #temp
setActiveInactiveField2 = 'Inactive'
where activeInactiveField1 = 'I'
select * from #Temp
drop table #Temp
Then you can databind the field in your webform to activeInactiveField2
Hello, Thank you for the quick response. Below is my code. As stated I am a newbie and the filed I am working with is status. Thanks a lot.
<%@.PageLanguage="VB"AutoEventWireup="false"CodeFile="Default2.aspx.vb"Inherits="Default2" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title></head>
<body>
<formid="form1"runat="server">
<div>
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"DataSourceID="SqlDataSource1"
Style="z-index: 100; left: 0px; position: absolute; top: 0px">
<Columns>
<asp:BoundFieldDataField="Citation"HeaderText="Citation"SortExpression="Citation"/>
<asp:BoundFieldDataField="Type"HeaderText="Type"SortExpression="Type"/>
<asp:BoundFieldDataField="Status"HeaderText="Status"SortExpression="Status"/>
<asp:BoundFieldDataField="Last Name"HeaderText="Last Name"SortExpression="Last Name"/>
<asp:BoundFieldDataField="First Name"HeaderText="First Name"SortExpression="First Name"/>
<asp:BoundFieldDataField="Middle"HeaderText="Middle"SortExpression="Middle"/>
<asp:BoundFieldDataField="DOB"HeaderText="DOB"SortExpression="DOB"/>
<asp:BoundFieldDataField="Violation Date"HeaderText="Violation Date"SortExpression="Violation Date"/>
<asp:BoundFieldDataField="Charge"HeaderText="Charge"SortExpression="Charge"/>
<asp:BoundFieldDataField="Description"HeaderText="Description"SortExpression="Description"/>
<asp:BoundFieldDataField="Disposition"HeaderText="Disposition"SortExpression="Disposition"/>
<asp:BoundFieldDataField="Cost"HeaderText="Cost"SortExpression="Cost"/>
<asp:BoundFieldDataField="Paid"HeaderText="Paid"SortExpression="Paid"/>
<asp:BoundFieldDataField="Balance"HeaderText="Balance"SortExpression="Balance"/>
</Columns>
</asp:GridView>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:MUNI_COURTConnectionString4 %>"
ProviderName="<%$ ConnectionStrings:MUNI_COURTConnectionString4.ProviderName %>"
SelectCommand="SELECT * FROM [MUNI_COURT_REC]"></asp:SqlDataSource>
</div>
</form></body>
</html>
You can handle this in RowDataBound event of the gridview. To add this event to your gridview, when in design view of Visual Studio, click on gridview once to get the properties window. From that, go to the events window (identified by a small "lightning" icon) and look for RowDataBound event. Double click on this event and an event hadler will created in your code file. Just copy and paste this code there.
protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e) {if (e.Row.RowType == DataControlRowType.DataRow) {if(e.Row.Cells[7].Text =="A") { e.Row.Cells[7].Text ="Active"; }else { e.Row.Cells[7].Text ="Inactive"; } } }Or you can change your select statement - something like select case status when 'i' then 'inactive' else 'active' end as status from blah blah blah...
By the way, it's never good practice to do a select *.
Hi, try this inline IIF statement to evaulate the status field and display conditional text. You will have to first convert your GridView to a template so you have control over the HTML controls.
<asp:LabelID="LabelStatus"runat="server"Text='<%# IIF(CONVERT.ToString(Eval("Status"))="A","Active", "Inactive") %>'></asp:Label>
Thanks I got that suggestion to work in a gridview and formview.
What if I had another field called type that I had to change
"H" to "Harbor"
"C" to "Civil"
"T" to "Traffic"
"L" to "Local"
You can use the same solutions that are marked as answer to extend the functionality. Like in mine, you can access the columns by their index (0 based). So whatever the index of your "Type" column, access it in RowDataBound event, check the text of the cell, and change it accordigly.
Sorry bullpit,
when I run your suggestion I get the following error message
Compiler Error Message:BC30205: End of statement expected.
I believe your suggestion would work best.
I forgot to uncheck the answer message button
Paste your code here. Please use the InsertCode option in the text editor.
Partial Class Default2 Inherits System.Web.UI.Page Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBoundprotected void gridView1_RowDataBound(object sender, GridViewRowEventArgs e) {if (e.Row.RowType == DataControlRowType.DataRow) {if(e.Row.Cells[7].Text =="A") { e.Row.Cells[7].Text ="Active"; } Else { e.Row.Cells[7].Text ="Inactive"; } } } End SubEnd Class
Thanks
learn_asp_fast:
Partial Class Default2 Inherits System.Web.UI.Page Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBoundprotected void gridView1_RowDataBound(object sender, GridViewRowEventArgs e) {if (e.Row.RowType == DataControlRowType.DataRow) {if(e.Row.Cells[7].Text =="A") { e.Row.Cells[7].Text ="Active"; } Else { e.Row.Cells[7].Text ="Inactive"; } } } End SubEnd Class
The piece of code I posted was an event handler for RowDataBound event. An event handler is a method (function) by itself. What you did was that you attached an event handler the way I mentioned (by double clicking the RowDataBound event in designer) but also copied and pasted the event handler that I posted into the event handler that the designer generated. So now you have a function defined in another function, which is not right. Morover, you are using VB and the code I pasted was C#. Change the above code to this:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBoundIf e.Row.RowType = DataControlRowType.DataRowThen If e.Row.Cells(7).Text ="A"Then e.Row.Cells(7).Text ="Active"Else e.Row.Cells(7).Text ="Inactive"End If End If End Sub
Bullpit,
Thank you very much for your time. I did realize I pasted the code into another function, but neith er way worked for me. I should be able to get this sample to work in other ways for me.
This a very helpful board.
Also, change the column index (7 in the code I posted) to the column index where you want to change the text. That might be the problem. For example, in your gridview, the "STATUS" colum index maybe 4 instead of 7.
Bullpit,
If you do not mind hopw do I get that to work in a Formview?
Thanks in advance
Substitute Values in Column in Gridview
the "DayOfWeek" column is actually an integer where 0 = Daily, 1=Sunday,
2=Monday, etc. How can I change what is displayed in the column from values
like 1or 2 to "Sunday", "Monday"?
============== Code =================
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
<Columns
<asp:BoundField DataField="EventName" HeaderText="EventName"
SortExpression="EventName" /
<asp:BoundField DataField="DayOfWeek" HeaderText="DayOfWeek"
SortExpression="DayOfWeek" /
<asp:BoundField DataField="Occurs" HeaderText="Occurs"
SortExpression="Occurs" /
<asp:BoundField DataField="Location" HeaderText="Location"
SortExpression="Location" /
</Columns
</asp:GridViewI finally found an example that I could apply. I created a Select Case
function named GetDayOfWeek to return the string I wanted for each case and
then replaced the Bound Column in the ASP code to:
<asp:TemplateField HeaderText="Day of Week"
<ItemTemplate
<%#GetDayOfWeek(CInt(Eval("DayOfWeek")))%
</ItemTemplate
</asp:TemplateField
Wayne
"Wayne Wengert" <wayneSKIPSPAM@.wengert.org> wrote in message
news:ut%232Q9SRGHA.4696@.tk2msftngp13.phx.gbl...
>I have a Gridview bound to an SQLDataSource (see code below). The value of
>the "DayOfWeek" column is actually an integer where 0 = Daily, 1=Sunday,
>2=Monday, etc. How can I change what is displayed in the column from values
>like 1or 2 to "Sunday", "Monday"?
>
> ============== Code =================
> <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
> AllowSorting="True"
> AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
> <Columns>
> <asp:BoundField DataField="EventName" HeaderText="EventName"
> SortExpression="EventName" />
> <asp:BoundField DataField="DayOfWeek" HeaderText="DayOfWeek"
> SortExpression="DayOfWeek" />
> <asp:BoundField DataField="Occurs" HeaderText="Occurs"
> SortExpression="Occurs" />
> <asp:BoundField DataField="Location" HeaderText="Location"
> SortExpression="Location" />
> </Columns>
> </asp:GridView>
Substring operation
hi
I wonder of someone can help me with this Substring operation.
I have : "12.10" or "120.10"
Now I want to convert these values to : "1210" or "12010"
Basically, I want to removce the dot within my strings. How can I do this.?
Thanks
string text = "12.10";
text = text.Replace(".", "");
Subtracting Quantities
Hi,
I have a query about updating quantity values within an website written in asp.net 1.1, vb2003 which references an access database. Basically what I want to do is when the customer confirms their order, I want then the number of items purchased to then be subtracted from the Products table in the database. Thus this ensures the number of each item in stock is kept up to date within the database.
My checkout table contains the intCartitemID (autonumber), Cart ID (random number and date value), quantity ordered and the productID for the item purchased.
The products table contains the ProductID, description, attributes, sale price and quantities in stock.
Now I assume I need to take the quantity of item purchased from the checkout table and then subtract this value from the products table. However, how do I put this idea into practice in terms of the asp.net coding ?
Any online examples of coding would help.
Thanks,
Just pass it in a SQL query
"Update productsTable set quantity = quantity - 1 where productID = " & productID
I agree with the above, except not "quantity = quantity - 1" ... but rather "quantity = quantity - @.howMuchWasOrdered"
Thanks both...
Monday, March 26, 2012
Suggestion
I am working on a e-commerce application, which should
allows me to add three values each time I add the items to
the basket. Now I wonder where and how I should store
these values so that I can reuse them in the next screen?
Please advise me.Two options that come to mind are in a database, and in the Session
object. Which one you pick really depends on the requirements of your
application. For instance, if you want a user to be able to add three
items to the shopping cart and come back three days later, you'll need
a persistant data store like a database.
You might want to check out the source code to the Commerce Starter
Kit: http://asp.net/Default.aspx?tabindex=8&tabid=47 This is a
learning tool and will give you some implementation ideas.
--
Scott
http://www.OdeToCode.com/blogs/scott/
On Wed, 15 Dec 2004 16:42:07 -0800, "Vishal"
<anonymous@.discussions.microsoft.com> wrote:
>Hello,
> I am working on a e-commerce application, which should
>allows me to add three values each time I add the items to
>the basket. Now I wonder where and how I should store
>these values so that I can reuse them in the next screen?
>Please advise me.
Suggestion
I am working on a e-commerce application, which should
allows me to add three values each time I add the items to
the basket. Now I wonder where and how I should store
these values so that I can reuse them in the next screen?
Please advise me.Two options that come to mind are in a database, and in the Session
object. Which one you pick really depends on the requirements of your
application. For instance, if you want a user to be able to add three
items to the shopping cart and come back three days later, you'll need
a persistant data store like a database.
You might want to check out the source code to the Commerce Starter
Kit: http://asp.net/Default.aspx?tabindex=8&tabid=47 This is a
learning tool and will give you some implementation ideas.
Scott
http://www.OdeToCode.com/blogs/scott/
On Wed, 15 Dec 2004 16:42:07 -0800, "Vishal"
<anonymous@.discussions.microsoft.com> wrote:
>Hello,
> I am working on a e-commerce application, which should
>allows me to add three values each time I add the items to
>the basket. Now I wonder where and how I should store
>these values so that I can reuse them in the next screen?
>Please advise me.
Saturday, March 24, 2012
Sum Calculation Query
Hi,
Within an access database I want to be able to add some values and calculate the sum of these values. Using asp.net 1.1. with vb.net, how would I achieve this ?
Presumably I could perform a look up within the databse and then use sind kind of function to add the required values ? Can anyone offer any suggestions or point to any useful online examples ?
Thanks,
reather than use asp.net to add up your columns why not use your datasource to do this.
like an sql query:
select sum(amount)
From TBLIntegerHolder
where amount > 0
something like that
Write a query within access to do the necessary data manipulation and the read the result.
Hi,
Use sum() function in the sql query.
Thanks all
SUM LIST By Month and Year - HELP PLEASE!
{
I need to loop through a list, find the amounts for the same month and year. How can I find all the values for a month and year, add them and set them to an new variable?
Below is the codle of the list I am using to Loop and its results, thank you for your help!
Response.Write("<table border=1 class=tdRowCenter width=300>");foreach(GenericList AmonuntsLoopin MyList)Response.Write(<SPAN class=st>"<tr><td>Month</td><td>"</SPAN> + AmonuntsLoop.Month + <SPAN class=st>"</td><td>Year</td><td>"</SPAN> + AmonuntsLoop.Year + <SPAN class=st>"</td><td>Amount</td><td>"</SPAN> + AmonuntsLoop.MonthlyAmount + <SPAN class=st>"</td></tr>"</SPAN>);
}
Response.Write(<SPAN class=st>"</table>"</SPAN>);
output for testing only
Month 1 Year 2006 Amount 17722.94 Month 2 Year 2006 Amount 18093.19 Month 3 Year 2006 Amount 18157.50 Month 4 Year 2006 Amount 16371.90 Month 5 Year 2006 Amount 17338.10 Month 6 Year 2006 Amount 17345.06 Month 7 Year 2006 Amount 18921.64 Month 8 Year 2006 Amount 18836.68 Month 9 Year 2006 Amount 20741.74 Month 10 Year 2006 Amount 17362.87 Month 11 Year 2006 Amount 15228.85 Month 1 Year 2005 Amount 17138.79 Month 2 Year 2005 Amount 16802.48 Month 3 Year 2005 Amount 18000.43 Month 4 Year 2005 Amount 16040.48 Month 5 Year 2005 Amount 9755.48 Month 6 Year 2005 Amount 19097.73 Month 7 Year 2005 Amount 18267.06 Month 8 Year 2005 Amount 18832.51 Month 9 Year 2005 Amount 20163.64 Month 10 Year 2005 Amount 16937.13 Month 11 Year 2005 Amount 16114.66 Month 12 Year 2005 Amount 18602.90 Month 1 Year 2006 Amount 22209.40 Month 2 Year 2006 Amount 20738.59 Month 3 Year 2006 Amount 18499.77 Month 4 Year 2006 Amount 21951.75 Month 5 Year 2006 Amount 19402.30 Month 6 Year 2006 Amount 21563.31 Month 7 Year 2006 Amount 22855.29 Month 8 Year 2006 Amount 26106.09 Month 9 Year 2006 Amount 22854.72 Month 10 Year 2006 Amount 25766.62 Month 11 Year 2006 Amount 19548.18 Month 1 Year 2005 Amount 20765.76 Month 2 Year 2005 Amount 20233.43 Month 3 Year 2005 Amount 19161.78 Month 4 Year 2005 Amount 20528.22 Month 5 Year 2005 Amount 18855.83 Month 6 Year 2005 Amount 20129.81 Month 7 Year 2005 Amount 21382.53 Month 8 Year 2005 Amount 25826.96 Month 9 Year 2005 Amount 22054.56 Month 10 Year 2005 Amount 25469.49 Month 11 Year 2005 Amount 22037.02 Month 12 Year 2005 Amount 21151.57
For example I need to add 1/2005 entries and end up with39,932.34
This is pretty crude, but you could do something like this...
1string curMonth ="";2string curYear ="";34double totalMonth = 0;5double totalYear = 0;67foreach(GenericList AmountsLoopin MyList)8{9// suggestion on writing your html line10 Response.Write(String.Format("<tr><td>{0}</td></tr>", AmountsLoop.Month)11 totalMonth += AmountsLoop.MonthlyAmount;12 totalYear += AmountsLoop.MonthlyAmount;1314if (AmonuntsLoop.Month != curMonth)15 {16 Response.Write(String.Format("{0}'s total is {1:c}", curMonth, totalMonth));17 curMonth = AmonuntsLoop.Month;18 totalMonth = 0;19 }2021if (AmonuntsLoop.Year != curYear)22 {23 Response.Write(String.Format("{0}'s total is {1:c}", curYear, totalYear));24 curYear = AmonuntsLoop.Year;25 totalYear = 0;26 }27}28Thanks, but is there another non crude way using Generics? I have the data in a Generic List
sum of column in footer
the footer of that column? anyone try this before? thanks!Hi,
you can do it by handling RowRataBound event of the GridView. Calculate sums
in it (as it's repeated for every row) and when GridViewRow's RowType is
Footer, place the sum value into it (for example by using a TemplateField
having Label in footer to which you set the sum, as it's Text value)
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Smokey Grindle" <nospamhere@.dontspam.net> wrote in message
news:efKT5aInGHA.4352@.TK2MSFTNGP02.phx.gbl...
> Is there a way to sum all the columns values in a gridview and show it in
> the footer of that column? anyone try this before? thanks!
>
hello smokey
here's a working code example. hope it helps
http://authors.aspalliance.com/aspx...wdatabound.aspx
hello smokey
here's a working code example. hope it helps
http://authors.aspalliance.com/aspx...wdatabound.aspx
thanks everyone!
"ReyN" <rvnunez@.yahoo.com> wrote in message
news:1151736818.909778.118790@.m79g2000cwm.googlegroups.com...
> hello smokey
> here's a working code example. hope it helps
> http://authors.aspalliance.com/aspx...wdatabound.aspx
>
sum of column in footer
the footer of that column? anyone try this before? thanks!Hi,
you can do it by handling RowRataBound event of the GridView. Calculate sums
in it (as it's repeated for every row) and when GridViewRow's RowType is
Footer, place the sum value into it (for example by using a TemplateField
having Label in footer to which you set the sum, as it's Text value)
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Smokey Grindle" <nospamhere@.dontspam.net> wrote in message
news:efKT5aInGHA.4352@.TK2MSFTNGP02.phx.gbl...
> Is there a way to sum all the columns values in a gridview and show it in
> the footer of that column? anyone try this before? thanks!
>
hello smokey
here's a working code example. hope it helps
http://authors.aspalliance.com/aspx...wdatabound.aspx
hello smokey
here's a working code example. hope it helps
http://authors.aspalliance.com/aspx...wdatabound.aspx
thanks everyone!
"ReyN" <rvnunez@.yahoo.com> wrote in message
news:1151736818.909778.118790@.m79g2000cwm.googlegr oups.com...
>
> hello smokey
>
> here's a working code example. hope it helps
>
> http://authors.aspalliance.com/aspx...wdatabound.aspx
>
Thursday, March 22, 2012
Supress repeating values in gridview
Customer wants a gridview displaying individuals who have taken part
in courses. The gridview should be sorted by the name of the
participant. If a person has taken part in several courses, the name
should only be stated once. Example:
Course Participant Date
Skateboarding John Doe May 1st 2007
Sailing Mary Doe June 5th 2007
Skateboarding June 10th 2007
Parasailing Ken Foll June 8th 2007
Since Mary has taken part in two courses (sailing and skateboarding)
her name should be stated only once.
How can I achieve this?
TIA
Regards!Handle the gridview's PreRender event. In the event loop through the Rows
collection, detect rows with the same Participant values and replace
repeating values with empty string.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
<Swede.Swede@.gmail.comwrote in message
news:1189456778.612104.325910@.22g2000hsm.googlegro ups.com...
Quote:
Originally Posted by
Hello!
>
Customer wants a gridview displaying individuals who have taken part
in courses. The gridview should be sorted by the name of the
participant. If a person has taken part in several courses, the name
should only be stated once. Example:
Course Participant Date
Skateboarding John Doe May 1st 2007
Sailing Mary Doe June 5th 2007
Skateboarding June 10th 2007
Parasailing Ken Foll June 8th 2007
>
Since Mary has taken part in two courses (sailing and skateboarding)
her name should be stated only once.
How can I achieve this?
>
TIA
>
Regards!
>