|
I am just starting to use ASP and am very green to its data structures, so I'm probably going about this completely wrong. On the C# side I have connected to the database and taken the info I need, but I need to strip the string of the extension before it's displayed on the asp side. Without the whole table and databinding, I would feel confident doing this, but with these two factors I'm not sure how to go about this. Is there any easy way to make my query into a table and then edit that table's entries, and set that to the datasource for binding, or am I looking at this the wrong way?
SqlConnection conn = new SqlConnection(ConnectionPath);
conn.Open();
string queryClasses = "SELECT WSS_Content.dbo.AllDocs.LeafName FROM
WSS_Content.dbo.AllDocs LEFT OUTER JOIN WSS_Content.dbo.RecycleBin ON WSS_Content.dbo.AllDocs.Id =
WSS_Content.dbo.RecycleBin.DocId WHERE (WSS_Content.dbo.RecycleBin.DocId IS NULL) AND (WSS_Content.dbo.AllDocs.Extension = 'zip')";
SqlCommand availableClasses = new SqlCommand(queryClasses, conn);
SqlDataReader reader = availableClasses.ExecuteReader();
SQLQueryClassListings.DataSource = reader;
SQLQueryClassListings.DataBind();
reader.Close();
<asp:GridView ID="SQLQueryClassListings" AutoGenerateColumns="false" runat="server"
BorderWidth="1px" BackColor="White" CellPadding="5" BorderColor="DodgerBlue" HeaderStyle-
BackColor="#0147FA" HeaderStyle-ForeColor="White">
<Columns>
<asp:BoundField HeaderText="Class Titles" DataField="LeafName" />
<asp:ButtonField ButtonType="Button" HeaderText="Register" Text="Register"/>
</Columns>
</asp:GridView>
|
|
|
|
|
Ideally you would edit your data source before binding, by doing substrings inside your SQL. You can also iterate over the data source before binding. You can also write your column definition so that it calls a method and passes in the data source, so you can return whatever string you like based on the data.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I don't think substring will work for me because the column I am selecting has differing string lengths and from what I googled, it appears I need to know the length of the string I wish to keep. Perhaps there is a sql command I missed.
I was trying to do a while loop "while(reader.Read())", but I wasn't sure exactly how to handle the reader contents. I had assumed that since it is a reader that I cannot write to its contents. Am I wrong in this assumption? I had tried to assign each iteration of reader to a string array, but that does not appear to be the path I wish to go down. My main issue is understanding what data type is coming out of reader and what format its data must be to be accepted during databinding. So, am I right about the reader and is the table idea bad? Thanks!
|
|
|
|
|
OK, it looked to me like you wanted to drop the extension, so, the last four characters.
VengefulSakhmet wrote: I was trying to do a while loop "while(reader.Read())"
I would fill a dataset and iterate over that.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
You can try something like:
string queryClasses = "select left(WSS_Content.dbo.AllDocs.LeafName, charindex('.', WSS_Content.dbo.AllDocs.LeafName, 0) - 1) from ...
Instead of charindex you might want lastIndexOf kind of thing.
Please check this link: http://www.sqlservercentral.com/scripts/T-SQL+Aids/31116/[^]
Hope this will help.
|
|
|
|
|
Hi,
I have a button in the ListView ItemTemplate. If th euser clicks the button I need to hide the button and show a value instead.
Here's my code
((Button)lvID.FindControl("btnSearch")).Visible = false;
((Label)lvID.FindControl("lblDynLabel")).Text = getItem;
It gives the following error:
Object reference not set to an instance of an object.
|
|
|
|
|
WEll, your code is awful. You should never use FindControl and not check if the return is null.
Unless the getItem is generated on the server side, I'd do this with javascript. Otherwise, I'd use a breakpoint and try to work out what was going wrong. Is lvID the listviewitem ?
Since when does ASP.NET have listviews ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
protected void lvID_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item is ListViewDataItem)
{
ListViewItem item = (e.Item as ListViewItem);
Button btn = item.FindControl("btnSearch") as Button;
btn.ForeColor = Color.Red;
}
// if not set AlternatingItemTemplate you have get error.
// must be AlternatingItemTemplate delete or set.
|
|
|
|
|
Hi,
I have encountered to an ASP.NET application for first time that forced me to provide some reports in it from data that hosted in a SQL Server 2008, in Visual Studio.NET 2008(Providing data by ADO.NET). Can anyone help me by providing some quick tutorials for me?
Thanks...
modified on Friday, August 21, 2009 5:15 AM
|
|
|
|
|
Please see following code,
1: Forecolor does not have any effect, the text is always one shallow blue, not red!
2: I want to change the text color with mouseover, but it has no effect!
anyone can give me one hint? What is more, I found that if DisplayMode="Text", the Forecolor has effect!
<style type="text/css"> .lnk { color:Green; } .lnk:hover { color:Aqua; } </style>
<asp:BulletedList ID="BulletedList1" runat="server" ForeColor="Red" DisplayMode="LinkButton" BulletStyle="CustomImage"
BulletImageUrl="~/images/bbb.gif" DataTextField="BookType" DataSourceID="SqlDataSource1" CssClass="lnk"
>
</asp:BulletedList>
thank you!
|
|
|
|
|
I am using Visual Studio 2008 and would like to know if I can create a nice glossy, rounded-corner button by deriving from the ASP.NET button class ???
|
|
|
|
|
I'm sure you can. However, the only way to create the look you want, is to skin your button with bitmaps. I'm not sure you need to extend a class to do that.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I know in previously could see the "hidden" block of code where all the declaration of the event handlers for each event even those of the page load. Where did this code go? Can I still see this code or is it now a black box? C# or VB.
vbwrangler
St Louis, MO
|
|
|
|
|
Are you referring to the designer file?
There is no designer file if you have created a "website". A designer file is created only for the web application project.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Hi,
I have an Ajax ModalPopupExtender which contains several textboxes and two buttons, save and close. The problem I am having is that when I use the tab key to move between TextBoxes the ModalPopupExtender loses focus and the focus moves outside of my web page, usually the browser's address bar gets the focus.
Anyone else experienced this? If so, did you manage to solve it and how?
Thanks for your time
|
|
|
|
|
I guess you will manually need to set focus on the first textbox in the modal popup. You can do that in the on showing event of the popup through javascript.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Thanks for your reply but I have actually tried that. Even then, when I tab from the first TextBox the browser's address bar gets the focus.
I will check over my code once more see if I have overlooked something. Thanks again for your time
|
|
|
|
|
Did you ever find a solution to this ?
|
|
|
|
|
yes, although I don't recall what the solution was! I will look when I get to work tomorrow.
|
|
|
|
|
|
I've got SQL Express 2005 and VS 2008 team.
As they specified in Pro ASP.NET 3.5 in C# 2008
1) run aspnet_regsql to generate say ProjMembership db
2) copied it into App_Data from SQLEXPRESS\data folder and attached its path in sseutil -a somepath\ProjMemebership ProjMembership
3) setup web.config as
<connectionStrings>
<add name="MyConnString"
connectionString="Data Source=.\SQLEXPRESS;
Integrated Security=SSPI;initial catalog=ProjMembership"/>
</connectionStrings>
<authentication mode="Forms" />
<membership defaultProvider="MyProvider">
<providers>
<add name="MyProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MyConnString"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
applicationName="/"
requiresUniqueEmail="true"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="3"
minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression="" />
</providers>
</membership>
<roleManager enabled="true" />
But when I go to security tab in ASP.NET configuration from VS, it reports:
Cannot open database "ProjMembership" requested by the login. The login failed. Login failed for user 'ACER\user'????
Чесноков
|
|
|
|
|
Connectionstring is missing Trusted User=True or say user id and password to login to sql server. Give a try by adding this.
Vijay V.
Yash Softech
|
|
|
|
|
Hi
lately, i got a problem with iis, when i try to start iis, i go this mesage :
Attempting start...
Start attempt failed.
IIS Admin Service or a service dependent on IIS Admin is
kely failed to start, which may mean that it's disabled.
when i go to service to start 'iis admin service' manually, i got this error :
Services
---------------------------
Could not start the IIS Admin Service service on Local Computer.
Error 2: The system cannot find the file specified.
---------------------------
OK
here is my event viewer log :
Event Type: Error
Event Source: Service Control Manager
Event Category: None
Event ID: 7000
Date: 8/20/2009
Time: 9:57:27 AM
User: N/A
Computer: MOSS
Description:
The description for Event ID ( 7000 ) in Source ( Service Control Manager ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: IIS Admin Service, %%2.
i have win 2003 server
1. i checked metabase.xml and MBSchema.xml file (copy from previous backup) but did not solved my problem.
2. i right-click on (%windir%\registration) folder and go to Properties > Security and found this users :
3. i log on to this machine as domain admin
Administrators : Does not have full permisson, Only Special Permissons has been checked
Everyone : Does not have full permisson, Only Special Permissons has been checked
SYSTEM : Does not have full permisson, Only Special Permissons has been checked
plz help me to workaround this problem.
thanks
|
|
|
|
|
What does ASP.Net has to do with this?
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Hi d@nish
i don't know, i can't see anything in iis manager.
|
|
|
|