SQL Server 2005 and VB.NET 2008 - vb.net

Guys please bear with me here, I've started using this blog to learn visual basics, I seriously want to learn and so far it been helping me a lot. Thank You everyone...
Now my question goes like this:.
Saying I have data in the SQL Server 2005 database and I want to retrieve data from the SQL table and display it on the textbox or listbox. I want to select Faculty_ID,Faculty_Name,F_Description from Faculty table and display these data on the textbox or listbox. And let's say I have my connection working just fine, I just need a statement to retrieve data from SQL table and display it on the textbox.
How do I do that? Please bear in mind you're helping the most stupiest, dumbest guy ever.
Thank You in Advanced!!!!!.

Repeaters are usually used to display data. Below is an example of a repeater. On the back end you can bind it to a list. I'd suggest making your own data structure and then binding it to that. By binding I mean, repeaterID.Datasource = yourDataObject and then repeaterID.Databind
<asp:Repeater ID="fieldList" runat="server">
<HeaderTemplate>
<table border="1" width="75%">
<tr>
<th>
<b>Object Field 1</b>
</th>
<th>
<b>Object Field 2</b>
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr id='<%#Eval("") %>'>
<td>
<asp:Label ID="obj1" runat="server" Text='<%# Eval("SQLObjectFieldRelName1") %>'></asp:Label>
</td>
<td>
<asp:Label ID="obj2" runat="server" Text='<%# Eval("SQLObjectFieldRelName2") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Text boxes and list boxes going to be less commonly used for any dataset. You'd only really use them for a string or some text. If that's what you want to do then I'd manufacturer your string in your code behind and set your textbox text to it.

Related

Web Server Controls Code Behind doesn't see my dataset configuration

I have 2 WebServer Controls
<asp:TextBox ID="txtTextBox" runat="server"ClientIDMode="Static"MaxtLength="30"Width="35px"CssClass="labeltext"></asp:TextBox>
<asp:DropDownList ID ="ddlDropDown" runat ="server" CssClass="text">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="U">someValue1</asp:ListItem>
<asp:ListItem Value="Y">someValue2</asp:ListItem>
<asp:ListItem Value="N">someValue3</asp:ListItem>
</asp:DropDownList>
There are no Errors on my aspx Page. I have configured my datasets to read the 2 new columns ( I even double checked the designer file for the dsd and see both new columns). I have cleaned and rebuilt my solution but my code behind (.vb) only see the dropdown and not the Text Box,
So it turns out, somehow the dataset got out of sync. I think it was because I tried to copy and paste a property in my aspx. I undid all my changes and re applied them again with no issue.

Date format in textbox [ASP.NET]

I have a grid which gets populate with data from my database. As part of my grid I have a view button which views the records in a modal form.
One of my records has a date. When the textbox in the modal form gets populated with the date it gets displayed like this: "2018/01/25 12:00:00 AM"
I want only the date to be displayed without the time. I have made sure that inside my SQL table that it is only date being saved and it is.
This is the column in my grid:
<asp:BoundField DataField="Date" HeaderText="Date" DataFormatString="{0:dd/MMM/yyyy}" SortExpression="Date"/>
This is my textbox:
<asp:TextBox ID="txtDate" runat="server" placeholder="Date" class="form-control"></asp:TextBox>
I have tried the following but it does not work:
txtDate.Text = Y.Date.ToShortDateString();
Text='<%#((DateTime)Bind("NewDate")).ToString("dd/MM/yyyy")%>'
Text='<%# Bind("JoinDate", "{0:MM-dd-yyyy}") %>'
I tried writing javascript code and limit the characters but the time still shows on load.
I would like only the date to be shown in my textbox.
Please advise. Thanks
change your grid code to this:
<asp:BoundField DataField="Date" HeaderText="Date" DataFormatString="{0:dd/MM/yyyy}" SortExpression="Date"/>
There are three Ms in date format, just remove one M, the format will be {0:dd/MM/yyyy}
I had to convert my date to a specific format in SQL.
I added this to my stored procedure in my select statement
CONVERT(VARCHAR(10), tb_Schedule.Date, 103) [Date]
This should work.
<asp:TextBox Text='<%#DataBinder.Eval(Container.DataItem,"Date", "{0:MM/dd/yyyy}")%>' ID="txtDate" runat="server" placeholder="Date" class="form-control"></asp:TextBox>
If you wish to directly bind your data, then add to the TextBox:
Text='<%# String.Format("{0:MM-dd-yyyy}", Eval("JoinDate")) %>'
I assume you wish to have two-way communication if you are using textbox, so use Eval instead of Bind.

configuring an HTML table

For a school assignment I have to revamp a website. I've been trying to make a table to include an image and buttons beside the image. I have the table set so the image (if you think of this an excel spreadsheet) is in A1, and A1 is as tall as B1, B2, and B3. So I want to have the large cell for the image and 3 cells, or rows rather, beside that to use as buttons.
I can't figure out how to do this, is it possible?
If I'm getting right what you are trying to achieve, I guess you should include rowspan attribute in one of the td tags (A1 cell).
<table border="1">
<tr>
<td rowspan="3">Picture Here</td>
<td>Button1</td>
</tr>
<tr>
<td>Button2</td>
</tr>
<tr>
<td>Button3</td>
</tr>
</table>
Looks like you need to read up on the 'rowspan' attribute for <table>

VB.net Precompiled site, and adding a template column with Date differences

I have a vendor application which is precompiled. I want to add a template column into the aspx page, however I'm having some difficulty.
This works for me fine as "Available" is a column bound to the asp DataGrid:
<asp:TemplateColumn HeaderText="test">
<ItemTemplate>
<asp:Label ID="Label2" Text='<% #DataBinder.Eval(Container.DataItem, "Available") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
Now, I'm trying to basically create a template column, that takes the (int) "Available" column and divide it by 12 and then multiply by DateTime.Now.Date.Month.
I'm not having any luck with using DateTime within <% %> on this page.
Thanks,
Mark
You can remove inherits="Archive, App_Web_XXXXX" from <%# Page %> then bring your code into ASPX file and modify it.

Adding checkbox control in datagrid at first column (vb.net 2003)

I am assigning a 'ds' dataset to datagrid.In addition to that I want to add new column with check boxes.That new column will be first column of datagrid.
Currently I am using below code,
DataGrid1.DataSource = dsResult.Tables("Result")
Result table has 4 column....in addtion to that i want to column "Selection" with check boxes
You can add a checkbox inside the itemtemplate like
<ItemTemplate>
<asp:CheckBox ID="chkComplete" runat="server" />
</ItemTemplate>
For a basic understanding read this article
Including a CheckBox Control Inside an ASP.NET DataGrid...