Jump to content
Xtreme .Net Talk

calvin

Avatar/Signature
  • Posts

    72
  • Joined

  • Last visited

Everything posted by calvin

  1. Hi, I have create number of Dataset which in App_code. I know how to use the table adapter to connect database and command in design page. But I need to get the data from dataset in codebehind. This is a real example I need to solve: In my database table, I need to access three column of data to analyze it and get the output I want. For example, the column1 is phone1, column2 is phone2 and column3 is phone3. So in my sql query, I do like this sql = "Select phone1, phone2, phone3 from mytable" Because I need to get this 3 column of data to put in my logic to get the output I want. Once the logic decide which column to use, then another logic will filtering the data and get the final out. For example, once decide to use column1 data, the data contain a long string, But I just need some of the character/string only. My problem is, how can I use the dataset which store in app_code to access the data and put in my logic. In asp.net 1.1, I can do like this : Dim ds as dataset . . . Dim getData As String = ds.Tables(0).Rows(s).Item("Phone1") If getData = ... Then .... End If In asp.net 2.0 ? Any solution and references are appreciated. Calvin
  2. Have a master page, need to inherit from a class(Core.vb) which store in "App_Code", inside the class file have many variable are declared and functions etc. In the master page, I have set CodeFileBaseClass = "Core" <%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" CodeFileBaseClass="Core" %> But I get Could not load type 'Core' error Anyone could help me?
  3. Oh, I omit to upload this part, but it still not working! ..... </ContentTemplate> <Triggers> <---Omitted Part <atlas:ControlValueTrigger ControlID="rblTest" PropertyName="SelectedValue" /> </Triggers> </atlas:UpdatePanel>
  4. Single page without inherit master page where postback without "Refresh the whole page" HTML Code: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Settings_TimeTable_Default" %> <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Test RadioButtonList Page</title> </head> <body> <form id="form1" runat="server"> <atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True"> <ErrorTemplate> Something Wrong to Script Manager </ErrorTemplate> </atlas:ScriptManager> <atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Conditional"> <ContentTemplate> <asp:RadioButtonList ID="rblTest" runat="server" AutoPostBack="True" OnSelectedIndexChanged="rblTest_SelectedIndexChanged" RepeatDirection="Horizontal"> <asp:ListItem>Hide</asp:ListItem> <asp:ListItem>UnHide</asp:ListItem> </asp:RadioButtonList> <asp:Label ID="lblMsg" runat="server" Text="Test Partial Rendering"></asp:Label> </ContentTemplate> </atlas:UpdatePanel> </form> </body> </html> Code Behind: Partial Class Settings_TimeTable_Default Inherits System.Web.UI.Page Protected Sub rblTest_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Select Case rblTest.SelectedValue Case "Hide" lblMsg.Visible = False Case "UnHide" lblMsg.Visible = True End Select End Sub End Class ------------------------------------------------------------------------- A page inherit master page where postback "Refresh the whole page" HTML Code: <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Copy of Default.aspx.vb" Inherits="Settings_TimeTable_Default" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <atlas:UpdateProgress ID="UpdateProgress1" runat="server"> <ProgressTemplate> <div id="progressBackgroundFilter"></div> <div id="processMessage"><br /><br /> <asp:Image ID="ImgLoading" runat="server" SkinID="ImgLoading" /> </div> </ProgressTemplate> </atlas:UpdateProgress> <atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Conditional"> <ContentTemplate> <asp:RadioButtonList ID="rblTest" runat="server" AutoPostBack="True" OnSelectedIndexChanged="rblTest_SelectedIndexChanged" RepeatDirection="Horizontal"> <asp:ListItem>Hide</asp:ListItem> <asp:ListItem>UnHide</asp:ListItem> </asp:RadioButtonList> <asp:Label ID="lblMsg" runat="server" Text="Test Partial Rendering"></asp:Label> </ContentTemplate> </atlas:UpdatePanel> </asp:Content> Code Behind: Partial Class Settings_TimeTable_Default Inherits System.Web.UI.Page Protected Sub rblTest_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Select Case rblTest.SelectedValue Case "Hide" lblMsg.Visible = False Case "UnHide" lblMsg.Visible = True End Select End Sub End Class
  5. Hi, I'm using ajax in my content page which contain several control in page. It could be like dropdownlist, button, gridview and radiobuttonlist. All control is working find except the radiobuttonlist, it always do the postback. Since I'm using master page to control all content page, I have no idea why is not functioning? Therefore, I create a single page without inherit the masterpage, the radiobuttonlist is working. So is it the masterpage problem? Part of the code: <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <atlas:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <atlas:ControlValueTrigger ControlID="RadioButtonList" PropertyName="SelectedValue" /> <atlas:ControlEventTrigger ControlID="Button" EventName="Click" /> <atlas:ControlValueTrigger ControlID="DropDownList" PropertyName="SelectedValue" /> </Triggers> <ContentTemplate> . . </ContentTemplate> </atlas:UpdatePanel> </asp:Content> Any help will be appreciate. Calvin
  6. Hi, I'm novice in asp.net 2.0. Since in version 1.1, when i call a select query to check is data available in database table, I use dataset to get the count of row if it is equal to zero, then do something... However, I found the feature no longer exist in version 2.0. So, Is anyone know how to do such a "function" to check the number of row return? Appreciate for any help and suggestion. Thank you. Calvin
  7. Hi, I got a Image gridview in a page. There is one delete button column to delete record. It is no problem to delete data in the database, but what I need is delete the image file as well if user click "OK" from the confirmation dialog. How can I get the "answer" whether user is click "OK" button or "Cancel" button? This is my code for delete the image record. OnClientClick="return confirm('Are you sure you want to delete this record?');" So, what method I should use for delete the image file? RowDeleting or RowDeleted. Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles GridView1.RowDeleting File.Delete(Server.MapPath(".\\") + "..Photo/" + imgName) End Sub Calvin
  8. Hi, I need to get child control to the gridview during edit mode. In fact I have a date field, during edit mode, the date will be in a textbox, beside the textbox is an image button. For what I need is if user click on the button, it will popup a calendar. After user selected the date, then calendar will automatic close. And that selected date will be place into the textbox. So, how do I get control to the image button which is in edititemtemplate? Is anyone can help me!! Calvin
  9. Hi, I try to use gridview with objectdatasource to obtain the images from the sql database. Within the database, a datafield is declare as "image" datatype. Now in my gridview, it doesn't show me the image instead of showing me a text "System.Byte[]" May I know how to solve it. What column I should use for the image? ImageField, TemplateField, Bound Field? Please help me!!! Calvin
  10. Get Solution from others Q_Quek wrote: 1: How can I set the "value" to the parameter? You can set the value in the Selecting event handler of the ObjectDataSource control. Q_Quek wrote: 2. Do I make mistake to the image field, since declare in database is "Image" datatype and use "Byte" in codebehind? No. Q_Quek wrote: 3: For next time if user want to retrieve the image, can it be "restore" as "image file"? Yes. You simply create a seperate web page or custom http handler for showing up an image store in DB, you can search for the sample code out there or on this site. Q_Quek wrote: 4. Can I use the "File Upload" control in "DetailsView" with objectdatasource? Because I have try to do it, but unsuccessful. Since I use the "Template Field" and drag the "File Upload" control to the "InsertItemTemplate", but there is no bound property of "text" which to bound to the "field binding". So, is this possible to use "file upload" control in DetailsView?? If so, how to do It. Yes, you can. You can define a select parameter for the ObjectDataSource control like this: <asp:Parameter Name="imgData" Type="Object" /> In the Selecting event handler of the ObjectDataSource, you can get the binary data of the uploaded image from the FileUpload control, then set it to the select parameter in the InputParameters collection: protected void ObjectDataSource1_Inserting(object sender, ObjectDataSourceMethodEventArgs e) { FileUpload upload = DetailsView1.FindControl("FileUpload") as FileUpload; using (BinaryReader reader = new BinaryReader(upload.PostedFile.InputStream)) { byte[] bytes = new byte[upload.PostedFile.ContentLength]; reader.Read(bytes, 0, bytes.Length); e.InputParameters["imgData"] = bytes; } } Q_Quek wrote: 5. With the approach in question 4, the DetailsView was include in the "atlas:UpdatePanel", will this make error? Yes, it may raise the error since the file does not get uploaded when you make an out-of-band request with Atlas, you need to submit the form to upload the image.
  11. Hi, I am using objectdatasource as datasource in page. I use the "File Upload" control to get the image and save to database. Within the database table, there are a lot of datafield. I got the problem of setting the parameter value for the image. I use three datafield to store the image relevant data. Datafield DataType 1. imgName (nvarchar 50) 2. imgData (Image) 3. imgType (nvarchar 50) Try Dim imgName As String Dim imgContentType As String Dim imgLen As Int32 Dim imgbin() As Byte If Me.FileUpload.HasFile = True Then If Me.FileUpload.PostedFile.FileName.Trim.Length > 0 And Me.FileUpload.PostedFile.ContentLength > 0 Then Dim imgStream As Stream = Me.FileUpload.PostedFile.InputStream() imgLen = Me.FileUpload.PostedFile.ContentLength imgContentType = Me.FileUpload.PostedFile.ContentType imgName = Me.FileUpload.PostedFile.FileName.Substring(Me.FileUpload.PostedFile.FileName.LastIndexOf("\") + 1) Dim imgBinaryData(imgLen) As Byte 'Dim n As Int32 = imgStream.Read(imgBinaryData, 0, imgLen) imgbin = imgBinaryData ObjectDataSource.InsertParameters("imgName") = imgName ObjectDataSource.InsertParameters("imgData") = imgbin ObjectDataSource.InsertParameters("imgType") = imgContentType ObjectDataSource.Insert() Question 1: How can I set the "value" to the parameter? 2. Do I make mistake to the image field, since declare in database is "Image" datatype and use "Byte" in codebehind? 3: For next time if user want to retrieve the image, can it be "restore" as "image file"? 4. Can I use the "File Upload" control in "DetailsView" with objectdatasource? Because I have try to do it, but unsuccessful. Since I use the "Template Field" and drag the "File Upload" control to the "InsertItemTemplate", but there is no bound property of "text" which to bound to the "field binding". So, is this possible to use "file upload" control in DetailsView?? If so, how to do It. 5. With the approach in question 4, the DetailsView was include in the "atlas:UpdatePanel", will this make error? Appreciate for those giving solution and help. Calvin
  12. Problem Solved. Solution: when you click your button you're not yet authenticated. You should try with the event loggedin : Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn Profile.xxx = xxx Profile.Save() End Sub
  13. Problem Solved. Solution: when you click your button you're not yet authenticated. You should try with the event loggedin : Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn Profile.xxx = xxx Profile.Save() End Sub
  14. problem solved. The inherit class was collide with others
  15. Hi, I was create a login page to authenticate user. When user click on the "Login" button, it will post value to couple of profile. Protected Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs) Profile.SchoolID = "School001" Profile.UserID = "A0001" Profile.Role = "admin" Profile.Save() End Sub I did set the DestinationPageUrl to my first page. I was using the master page with Navigation Menu. All of this if working, If a user is "admin" role and authenticated, then user will go to my first page(DestinationPageUrl) and get "admin" Menu. My problem is when user click the Login button, the database have store this new profile value. But when it come to the DestinationPageUrl, it change my new profile value to my default value. The default value is set in web.config page. So, the "admin" user get the default "menu" since his role has change to normal user. Web.config <anonymousIdentification enabled="true"/> <profile> <properties> <add name="SchoolID" defaultValue="EDU01" allowAnonymous="true"/> <add name="UserID" defaultValue="ES000" allowAnonymous="true"/> <add name="Role" defaultValue="user" allowAnonymous="true"/> <add name="MyThemes" defaultValue="Default" allowAnonymous="true"/> </properties> </profile> If anyone know what's wrong to my code? Calvin
  16. Can't get object control in the template Get this error "Object reference not set to an instance of an object." to the object in login template(SchoolID dropdownlist, textbox). Calvin
  17. Hi, I create a asp.net 2.0 website and a lot of page include a login page. I convert the login control to template because i want to add a dropdownlist which poses some value which is needed like schoolID. The login page is work fine, but what i need is when user authenticated, I want to store some value to the profile. Like SchoolID, Role, and UserID. So I add the code below to the login page. Login.aspx.vb Protected Sub LoginButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) If User.Identity.IsAuthenticated Then If User.IsInRole("admin") Then Dim ddlSchoolID As DropDownList = Me.LoginView1.FindControl("ddlSchoolID") Dim UserName As TextBox = Me.LoginView1.FindControl("UserName") Profile.SchoolID = ddlSchoolID.SelectedValue Profile.UserID = UserName.Text Profile.Role = "admin" End If End If End Sub Web.config <anonymousIdentification enabled="true"/> <profile> <properties> <add name="SchoolID" defaultValue="ABC01" allowAnonymous="true"/> <add name="UserID" defaultValue="A0001" allowAnonymous="true"/> <add name="Role" defaultValue="user" allowAnonymous="true"/> </properties> </profile> Because I need to use the Profile value when user logon (like use the value to create dynamic menu and so on. All the page is running, just cannot get the value from profile only. It always get the default value in web.config. I believe it must be something wrong in the login button event. Hope someone can help on this. Thank you. *Is anyone have some reference regarding popup calendar in gridview in editmode Calvin
  18. Is anyone know how to populating the menu by user role using SiteMapDataSource in vb code?I found a lot of code use the c#. I'm not familiar with that. "Login Page" <-this is simple login authentication page protected void Button1_Click(object sender, EventArgs e) { string userName = txtUserName.Text; if (userName.Equals("admin")) Response.Redirect("~/Admin/AdminHomePage.aspx"); else if (userName.Equals("user")) Response.Redirect("~/User/UserHomePage.aspx"); } "Class File - Navigation Manager" using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public class NavigationManager { public static SiteMapDataSource GetSiteMapDataSource(string role) { <--How to change to VB code??? string url = String.Empty; if (role.Equals("Admin")) <--- Question 1: How it get this role??, since txtUserName.Text is store in userName url = "~/AdminAdminHomePage.aspx"; else if (role.Equals("User")) url = "~/User/UserHomePage.aspx"; XmlSiteMapProvider xmlSiteMap = new XmlSiteMapProvider(); System.Collections.Specialized.NameValueCollection myCollection = new System.Collections.Specialized.NameValueCollection(1); myCollection.Add("siteMapFile", "Web.sitemap"); xmlSiteMap.Initialize("provider", myCollection); xmlSiteMap.BuildSiteMap(); SiteMapDataSource siteMap = new SiteMapDataSource(); siteMap.StartingNodeUrl = url; siteMap.ShowStartingNode = false; return siteMap; } } Anyone can help me to convert this "VB" code will be more appreciate. Calvin
  19. Thanks for your solution, problem solved
  20. I get this error after upgrading from asp.net 1.1 to 2.0 in our web hosting. "Request for the permission of type 'System.Security.Permissions.UIPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed." The page have add reference to System.Windows.Forms.dll. Below is part of my code: Dim x As Windows.Forms.Form = New Windows.Forms.Form Dim grp As Graphics = x.CreateGraphics() Dim stringFont As New Font("Arial", intFontSize) Dim stringSize As SizeF 'Measure String width stringSize = grp.MeasureString(strStudentName, stringFont) . . . The page have totally no bugs and running well. But get error when upgrading asp.net 1.1 to asp.net2.0 Anyone know the solution? Thanks for all help. Calvin
  21. Thanks to penfold69 and Joe Mamma, the query works Calvin
  22. Hi, I want to get all the student from a Database table which store student certificate. For example, I need a query of student who "HAVE" 3 certificate(Cert A, B, C). Certificate Table: StudentName CertificateName John Cert A Wilson Cert B John Cert B John Cert C Michael Cert A Output: John sqlQuery = "Select * from CertificateTable Where (CertificateName = 'Cert A') AND (CertificateName = 'Cert B') AND (CertificateName= 'Cert C')" This is my query, but it not works. Calvin
  23. Hi, I want to check the width of string in each row of particuluar column of datagrid. For example, there is a column binding student name and the column width is set to 170 px. The default font size is set to 8 point. Some of the student name exceed the length of row and it is wrapped. I want the system check width of student name on each row. So if it is exceed 170px, system will deduct the size of font until it is fit to the row width(something like shrink). I search a lot of articles and forum also suggest use "MeasureString"., but I face some error. Below is my code to check the string width: For i As Integer = 0 To DataGrid.Items.Count - 1 Dim intFontSize As Integer = 8 Dim intColumnWidth As Integer = 170 'px Dim intGetStringWidth As Integer Dim item As DataGridItem = DataGrid.Items(i) Dim measureString As String = item.Cells(2).Text 'Student Name Dim stringFont As New Font("Arial", intFontSize) Dim g As Graphics = Me.CreateGraphics <- Error 1 Dim stringSize As Double stringSize = g.Graphics.MeasureString(measureString, stringFont) <-Error 2 While stringSize > intColumnWidth intFontSize -= 1 stringFont = New Font("Arial", intFontSize) g = Me.CreateGraphics <- Error 1 stringSize = g.Graphics.MeasureString(measureString, stringFont) <-Error 2 End While item.Cells(2).Font.Size = FontUnit.Point(intFontSize) item.Cells(2).ForeColor = Color.Red Next Error 1 Message: CreateGraphics is not member of 'XXX.XXX' Error 2 Message: 'Graphics is not member of 'System.Drawing.Graphics' Anyone can help me!! Appreciate for any help and comments. Calvin
×
×
  • Create New...