VS 2012 - Set BGColor Based On SQLDatasources
May 7, 2013
How to set the bgcolor of an asp.net cell from code behind using a value from a sqldatasource?
I have a working sql data source that is used to populate labels in my html form using asp.net.
The background color of the cell depends on a comparison of the actual value versus the target value. If the actual daily value exceeds the limit I would like to change the bgcolor of a cell in the web page. The actual value comes from one datasource and the limit comes from a 2nd data source.
In vb code behind I would like to accomplish the following pseudo code:
If (sqlsource1Total > sqlsource2Limit) Then
bgXCell.BgColor = "#ccff99"
Else
bgXCell.BgColor = "#ff9999"
End If
View 3 Replies
Similar Messages:
Jul 9, 2013
I have an web app I'm developing and it contains a form with a gridview. The grid view has 2 dropdowns...cbo1, and cbo2
The gridview is in Edit mode and when I select something from cbo1, i need to re-populate cbo2.
Here's the source code that shows my grid and dropdowns:
Code:
<asp:GridView id="gridOutdoor" EnableViewState="false" onrowdatabound="gridOutdoor_RowDataBound" onrowediting="gridOutdoor_RowEditing" AutoGenerateColumns="False" runat="server" PageSize="5" CssClass="GridView" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" >
<Columns>
<asp:CommandField ShowEditButton="True" />
[Code] ...
Here's the sqlDataSource that's also in the source page:
Code:
<%-- cbo1--%>
<asp:SqlDataSource ID="SqlDataSourceProduct" runat="server" CancelSelectOnNullParameter="false" ConnectionString="<%$ ConnectionStrings:QuoteToolConnectionString %>"
SelectCommand="select distinct cat1 as Product from QuoteItems where accessory=0">
</asp:SqlDataSource>
<%-- cbo2--%>
[Code] ...
As you can see, for sqlDataSourceBodyColor, I have a param and it needs to get the value from the user's selection of cbo1.
In the RowDataBound event, I had set it up to get this value. It works great for the initial load of the page; but when I make a selection from cbo1, the value of cbo1 when debugging, is always what ever was first set when going into edit mode - the bound items.
here's the code for that:
Code:
Protected Sub gridOutdoor_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim cbo1 As DropDownList = CType(e.Row.FindControl("ddProduct"), DropDownList)
Dim cbo2 As DropDownList = CType(e.Row.FindControl("ddBodyColor"), DropDownList)
[Code] .....
View 1 Replies
May 18, 2015
I'm going to have a textbox on my ASPX page - where users can enter a number between 1-50.
Based on their selection, I'd like to add three textboxes for each number and number them appropriately.
I'd like three textboxes for each "number", so for example, the fields would be:
Name1, PIN1, Desc1
Name2, Pin2, Desc2
Name3, Pin3, Desc3
...
So, how do I, at runtime, add these fields to my page?
Secondly, This form, upon submittal, creates a configuration file on my server currently in the format of
[FIELD1]
FieldOne.Value
[/FIELD1]
[FIELD2]
FieldTwo.Value
[/FIELD2]
[FIELD3]
FieldThree.Value
[/FIELD3]
With those fields, it's rather easy, as the form has static controls that I'm looking up and sending to my file.
How would I add the dynamic controls to the file as well? Obviously, if they've selected to add 10 fields, I don't want 40 other fields of blank/nothing (since they can choose to add up to fifty). How would I iterate only adding the fields that they've chosen?
I'm writing in VB.NET not C
View 3 Replies
Jun 7, 2010
I have a MultiView control with 3 View controls inside it.
View1 contains a GridView control with 2 DataKeyNames assigned.
View2 contains a FormView and a DetailsView control.
View3 contains several DetailsView controls.
When a row is selected in the Gridview I'd like to update View2 to show data relating to the selected row DataKeyName 1 and View3 to show data relating to the selected row DataKeyNames 1 and 2.
I have previously tried configuring the SQLDataSource to use a WHERE clause setting the Source Control to the GridView object but I couldn't get it to work. There was nowhere to state which DataKeyName to use as the parameter.
View 1 Replies
Sep 5, 2012
How I would get the ID of the row that was inserted using the following? (VS2012 VB.NET)
Code:
Dim connString = ConfigurationManager.ConnectionStrings("DBConnectionString").ToString
Dim conn As New SqlConnection(connString)
[code]....
View 1 Replies
Jun 23, 2014
I need to create below layout using Div's. i should not use table to create this. also i need to do this with css and I have to use % for width and height. Any sample code. on the below image left border is missing. But I want that as well.
View 4 Replies
Jul 10, 2014
I have the following code:
HTML Code:
<html>
<head>
<script type="text/javascript" src="~/Scripts/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
[Code] .....
This code works fine for populating a div with html from a view. Where I'm having trouble is figuring out how to pass a string parameter to my view, so as to customize what the view returns. Passing a number doesn't seem to be a problem, but I can't get the string right. I need to know:
1. how to format the string in the url - or even if passing the string in url is right.
2. how to structure the route in routeConfig.
View 5 Replies
Jun 4, 2013
I have a gridview on a page where I display a list of items. One of the columns on the gridview is a hyperlink that sends a querystring to another page, which then displays the details of the selected item. It's your basic CRUD operation and it works great except for one thing: The query string has some information in it that I'd rather not be public. Is it possible to have a link or a button or some other sort of column that does a post to the new page instead of a querystring?
View 29 Replies
Dec 2, 2013
I need to produce a simple graphic which is a simple rectangle (bar) with a variable portion filled in to denote a percentage.
What is the best way to achieve this? I had a look at the .net charting tools but the nearest I could find to what I needed was the barchart which didn't quite seem to meet my needs for a single value.
View 1 Replies
Jul 10, 2013
I have a gridview that has 3 dropdowns. And when I am in edit mode, when updating via the RowUpdating event, I am not getting a value from my 2nd or 3rd drop downlists. Here's the code from RowUpdating:
Code:
Protected Sub gridOutdoor_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
'WHEN DEBBUGING, the text for ddBodyColor.Text is an empty string. I had selected a value prior to this event firing."
Dim ddBodyColor As DropDownList = DirectCast(gridOutdoor.Rows(e.RowIndex).FindControl("ddBodyColor"), DropDownList)
End Sub
Here's the source code for ddBodyColor:
Code:
<EditItemTemplate>
<asp:DropDownList ID="ddBodyColor" runat="server" TabIndex="2" AppendDataBoundItems="true" Enabled="true" DataTextField="bodyColor" DataValueField="bodyColor"><asp:ListItem Text="Select" Value="" /></asp:DropDownList>
</EditItemTemplate>
View 9 Replies
May 30, 2013
I have a form and I want to insert the current time at which the user clicks to insert into the table of my db.
When running, I get the following error when trying to insert into my sqldatasource:
"System.FormatException: String was not recognized as a valid DateTime."
What's wrong with my insert parameter?:
<InsertParameters>
<asp:Parameter Name="DateAdded" Type="DateTime" DefaultValue= "<% DateTime.Now %>" />
</InsertParameters>
View 6 Replies
Dec 30, 2015
I have created a single checkbox in the DetailsView of my Asp page. I then created VB code behind to set the value =1 if the checkbox is checked and value =0 if checkbox is not checked. I cannot get the code to work. The record will get created in my SQL database, but the checkbox field remains NULL
In SQL table, my field and datatype is: Greenfield, bit, NULL
The beginning code for DetailsView1 is:
Code:
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" BackColor="White" BorderColor="White" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" DataKeyNames="ID" DataSourceID="tblEntryFormDS" style="text-align: left; margin-bottom: 0px;" Font-Bold="False" Font-Names="Arial" Font-Size="Small" DefaultMode="Insert" GridLines="Horizontal" CssClass="auto-style47">
<AlternatingRowStyle BorderStyle="None" />
The code for the checkbox within DetailsView1:
Code:
<asp:CheckBox ID="CheckBox1" runat="server" Text=" Greenfield" AutoPostBack="True" />
And the VB code behind. I originally used OnCheckedChanged but that wasnt working and it was suggested of me to use DetailsView1_ItemInserting instead: (The Dropdownlists in the code are working)
Code:
Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles DetailsView1.ItemInserting
Dim DropDownList6 As DropDownList = CType(DetailsView1.FindControl("DropDownList6"), DropDownList)
Dim DropDownlist9 As DropDownList = CType(DetailsView1.FindControl("DropDownList9"), DropDownList)
[Code] ....
View 1 Replies
May 1, 2015
I'm trying to connected to a third-party server, that allows API access via XML post/response. I've created just a very simple test page with a button to press.... the button should just go to the URL, log in with basic authentication and then return the response. if I use a browser and go to the URL, I see the XML response. Usuing my app, I'm still getting 401 unauthorized. I've been at this for hours, I've searched the forums and googled extensively, still no luck. Also, this is an internal app to internal server so security is not the highest priority. I'm setting the UN and PWD for authentication in a simple form.
Here's my VB code behind:
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader
Dim result As String
'disables self-signed SSL cert errors
[Code] ....
And the username and password are 100% accurate - as I mentioned above the code (well, implied).
I feel like this SHOULD be pretty easy: Overall request for testing: Submit a web request to a URL, disable the SSL check (self-signed certs used), login with basic UN and PWD I supply, return the response to a textbox.
View 1 Replies
Feb 11, 2014
I have a class TicketOrder. It's not recognizing my lstSectionNumber (Tickets.TicketForm.lastSectionNumber is inaccessible due to its protection level).
Here is the code for TicketOrder class:
public class TicketOrder
{
public TicketOrder(TicketForm form)
{
this.form = form;
}
//Declare static variables
[Code] .....
This is my code behind:
public partial class TicketForm : System.Web.UI.Page
{
//Declare variables
int myInt;
TicketUser user = new TicketUser();
TicketOrder order;
[Code] .....
View 3 Replies
Sep 30, 2013
I have a web app and one of the forms has a gridview and also two tables.
Because of this, I have a save button that saves new data; and I also have update buttons that appear each time the user clicks Edit in a row of the gridview.
I would like to see if there's a way to combine my save with my update so that the user only has to click one time to save.
I was looking for the update button link that appears in my gridview via the source code page, but it's no where to be found.
Is there a way to move the update button or not show it? Not sure how to even start using the save to incorporate both.
View 2 Replies
Jul 16, 2015
how I can get item values in a ListView in code-behind? I’ve searched high and low during the past 2 days and tried various possibilities to no avail. Data binding is being done in code-behind:
Code:
SQLString = "SELECT Field1, Field2, Field3 FROM Table1"
DataTable1 = LoadDataTable(Connection1, "SELECT Field1, Field2, Field3 FROM Table1")
ListView1.DataSource = DataTable1
ListView1.DataBind()
ASP:
[code]....
The aim is that once a user clicks on a particular row in the ListView a pop-up is displayed which in turn reflects all data related to the record. For the purpose of preparing the data for the pop-up I need to determine the unique record identifier.
I have the same code working perfectly in another app, which has to effect that once a user clicks on a particular row in the ListView a new tab is opened which in turn reflects all data related to the record.
View 1 Replies
Jun 24, 2014
This is sort of a continuation of a previous thread: View thread
The requirement I have is to be able to have a popup form that shows detailed data on a facility. This would be available on various pages of the website where the user may want to drill down and see detailed information on a facility. We also want to allow the user to update the data on the facility if so desired. I have the code working to show the popup form and get the html for the popup from a view. Right now I'm setting the values of the input boxes using razor code that accesses the @model object. That's about as far as I've gotten.
Where I'm struggling is:
1. How to tie the data in the inputs back to the view model.
2. How to write the ajax code to write the data back to the server. I tried using a standard form, but that redirects the original page that popped up the form. I want to leave that page alone and just submit the data back to the server and close the popup.
Now my dev lead wants us to use the dojo toolkit for our javascript library. That would be OK if I already knew what I was doing with regard to web development, but I don't - and documentation is just not very good with regard to dojo. I'm still trying to figure out html and mvc, so I thought I'd see if I can get this scheme working with some other javascript library first, and then see about switching it over to dojo.
I've read some about knockout and jquery, but with everything being so new to me it's hard to get all this to gel in my head, and I'm not sure about my design. I've read some about mvc's built in ajax tools, but so far all I'm seeing is stuff related to getting data and displaying it - not about submitting data.
I'd like to be able to send the data back to the server in the same object structure that I extracted it with - something that matches the model. I think this is doable, but I'm not sure - and the 'how' of it is escaping me at this point.
View 20 Replies
Jul 6, 2015
I want to create a function that a web method will call - and that function will be in a DLL.
I am assuming that having that function in a DLL is better then leaving it as source since it won't recompile when IIS recycles or whatever schedule that falls under.
Do I need to make this function in a different project (solution) and compile it down to a DLL and then refer to that folder location in the WEB.CONFIG?
And I assume I just put it in the BIN folder in INETPUB - right? Do I need a WEB.CONFIG reference to it as well - in production?
View 9 Replies
Aug 20, 2014
A user inserts ad details and on button click saves them to database. If the save is successful, a DIV element slides down (becomes visible) allowing the users to add pictures for that ad.
As the users adds the pictures, they are being shown in a Repeater control. When you hover over a picture, a Delete button is displayed and when you click it, a confirmation message pops out asking the users if they really want to delete the picture.
Now this is where the problems begins. The code behind the button click doesn't wait for the user to click YES or NO. It just executes leaving the message displayed.
So to summarize:
- The entire "bottomDIV" element is wrapped inside an UpdatePanel with update mode set to "Conditional".
- Since the Button is inside the Repeater control, I cannot access its Click event. I use Repeaters ItemCommand to check for the correct Command Name.
- The Repeater Control is inside the same UpdatePanel
- The Update Panel has AsyncPostBackTrigger set to Repeater Control.
The HTML:
HTML Code:
<asp:UpdatePanel ID ="bottomUpdate" runat ="server" UpdateMode="Conditional" >
<ContentTemplate>
<div id ="bottomWraper">
<div id ="savePictureWraper" runat ="server" style="float:left; padding-top:3px;" >
<asp:TextBox ID ="pictureName" runat ="server" placeholder ="Naziv slike" style="width:181px;">
[Code] ....
The Script (using alertify.js to display the confirmation dialog):
HTML Code:
<script>
$("[id*=btnDeletePicture]").on("click", function () {
alertify.confirm("Confirm?", function (e) {
if (e) {
alertify.alert("Successful AJAX after OK");
[Code] ....
The code behind is simple and all it does it executes the delete statement and then calls the displayPictures sub again. So, why the code behind doesn't wait for the user to select an option in confirmation dialog....
View 1 Replies
Jul 30, 2014
I have error in vs 2012
The type or namespace name 'CrystalDecisions' could not be found (are you missing a using directive or an assembly reference?)
Error 18 The type or namespace name 'ReportDocument' could not be found (are you missing a using directive or an assembly reference?)
View 1 Replies
Aug 14, 2013
I am creating a web app using vs 2012. I am constantly having re-arrange my code because, each time I either scroll or move off the page, I go back and it's all jumbled up again. E.g.
<table><tr><td></td></tr></table> 'fixed nicely
scroll or move off the page:
<table> <tr>
<td>
</td></tr>
</table>
Is this just the way it is...or is there a way to fix it so it stays as how I put it?
View 3 Replies
Jun 9, 2015
I use a Treeview control like below code.. it cause page_load event twice.. how to stop page_load firing twice?
HTML Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="AdminSection_test" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
[Code] ....
View 16 Replies
Aug 1, 2013
I created tracking software, and now I need to create hundreds of web forms with specific names (within the same solution). Can this be accomplished with managed code or does it all have to be done manually? In case you are wondering what this is for - its to do market research using the keywords in unique URLs...so I just need to be able to create hundreds of them at once to hand to my classified ad poster.
View 2 Replies
Aug 19, 2013
I'm creating a simple CMS for a fairly simple web page. I'm currently working on a part for displaying news on the main page.
The controls I have on the page:
- a GridView control with enabled pagging and a SELECT button,
- an Image control for displaying news cover picture,
- CKeditor control for editing news text,
- Repeater control for displaying pictures from database
How does it all work?
In Page_load I have the following:
vb.net Code:
connectionString = "Data Source=KORISNIK-PCSQLEXPRESS;Initial Catalog=****;
User ID=**;Password=****" conn = New SqlConnection(connectionString)
If conn.State = ConnectionState.Closed Or conn.State = ConnectionState.Broken Then
Try conn.Open() If Not IsPostBack Then bindGrid()
[Code] ...
As you can see, I load the GridView control with news from DB. At this moment all other control are disabled. User has to SELECT the row he wants to edit, and click the MODIFY button.
This is what happens when user clicks the MODIFY button:
vb.net Code:
Private Function selectForEdit() dsSelectForEdit = New DataSet
captionPicture.ImageUrl = "" enableCommands()
Dim sqlQuery As String
sqlQuery = "SELECT news.newsCaption, news.newsIntro, news.newsCoverPicture, news.newsStatus,
[Code] ....
Basically, I select newsDetails based on newsID. Also, this is where I take the coverPicture from the database using a generic handler.
This is the code for showImage.ashx:
vb.net Code:
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim newsID As Int32 If Not context.Request.QueryString("newsID") Is Nothing Then
newsID = Convert.ToInt32(context.Request.QueryString("newsID")) Else
Throw New ArgumentException("No parameter specified") End If
[Code] ....
This part works fine, as the picture is correctly displayed in the Image control. Now, I also want to load the pictures that are related to the selected news. So, I use this function:
vb.net Code:
Private Function selectNewsPictures() dsSelectPicturesForEdit = New DataSet enableCommands()
Dim sqlQuery As String sqlQuery = "SELECT newsDetailsPictureID,newsDetailsPicture,newsDetailsPictureCaption,newsDetailsPictureDescription FROM newsDetailsPictures WHERE newsID = @newsIDEditing" myCommand = New SqlCommand(sqlQuery, conn) myCommand.Parameters.Add("@newsIDEditing", SqlDbType.Int, 250)
[Code] ....
You can see that I take pictureID's and store them into a List (of integer). That way I can use those integers in showNewsPictures.ashx to display all the pictures.
showNewsPictures.ashx:
vb.net Code:
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim newsID As Int32 If Not context.Request.QueryString("pictureID") Is Nothing Then
newsID = Convert.ToInt32(context.Request.QueryString("pictureID")) Else
Throw New ArgumentException("No parameter specified") End If
[Code] ....
The picture ID's are being sent through pictureRepeater_ItemDataBound:
vb.net Code:
Private Sub pictureRepeater_ItemDataBound(sender As Object, e As RepeaterItemEventArgs)
Handles pictureRepeater.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim ctrl As New Image ctrl = e.Item.FindControl("pictureHolder")
ctrl.Width = 100 ctrl.Height = 100 ctrl.ImageUrl = "~/showNewsPictures.ashx?pictureID=" &
listOfIDs.Item(itemIndex) itemIndex = itemIndex + 1 End If End Sub
THE PROBLEM:
I load the page, select the news, click the MODIFY button and all works well. The news details are loaded, the cover picture is loaded, the repeater pictures are loaded.
I click the cancel button (clears all the commands and disables them) and I get an error saying the DataReader needs to be closed.And I never use one This happens either in showNewsPictures.ashx or showImage.ashx.
In some other scenario, this happens right after I click the MODIFY button.
View 1 Replies
Aug 16, 2012
When i right click on a table in database explorer i do not get the option to "show table data" the way i have in every other previous version.
View 2 Replies