Getting Started with .net and a few questions


Hello
 I've done some asp and php programming along with various other languages in the past and slowing getting my head around .net.
I have a small project of creating a Holiday Booking system on our Intranet and just trying to get the first part to work properly will hopefully get me sorted for the whole project. The Intranet is running on .net 2 and I prefer to use the VB code rather than C#. This is connecting to an SQL server.
My initial page that I am trying to create is just for an admin user to view which dates in a table have been specified as Bank Holidays and be able to add new dates or delete existing dates. As we work across UK and Ireland there are 3 regions for different bank holidays.
So my initial form  starts off with a combo box to select the Region, when that is changed it then populates another combo with the years in the table against the selected region. When that is changed a grid view is shown displaying all of the dates for that region in that year. The grid view works fine in that the user can also delete the dates.My main issue at the moment is with the new additions. I have a form where the user clicks on the New button and teh ID field and a calendar control is displayed. I just don't know how to populate the ID field at the moment from a non form combo box.
Also my boss is an SQL programmer so would prefer to run everything as SP's on the server. So can somone also let me know which would be better to run the SQL from the controls or call SP's? Is there any load difference if this was to run on very large databases? I'm also quite happy at the moment about using the local SQL commands as in teh code below but not sure how to call an SP, so a small posting on how to do that would be most appreciated in replacemtn for part of my code.
 The code below is a sample of what I am working on at the moment.
 Thanks in advance for any replies.
Langy
 
<script runat="server">
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
GridView1.DataBind()
End Sub

Protected Sub btnAddDate_Click(ByVal sender As Object, ByVal e As System.EventArgs)

End Sub

Protected Sub Calendar2_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = sender.SelectedDate
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
text-align: center;
}
.style2
{
width: 600px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="style1">

<div class="style1">



Please Select a Region:
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="NIL_HOL_Region"
DataTextField="RegionName" DataValueField="ID"
OnTextChanged="DropDownList1_SelectedIndexChanged"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True">
</asp:DropDownList>
</div>
<asp:SqlDataSource ID="NIL_HOL_Region" runat="server"
ConnectionString="<%$ ConnectionStrings:NIL_HOL DBConnectionString %>"
SelectCommand="SELECT [ID], [RegionName] FROM [Regions] ORDER BY [RegionName]">
</asp:SqlDataSource>
<div class="style1">



Please Select a Year:
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="NIL_HOL_Years"
DataTextField="PubHolYearsTxt" DataValueField="PubHolYears"
OnTextChanged="DropDownList1_SelectedIndexChanged"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True" onprerender="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
</div>
<asp:SqlDataSource ID="NIL_HOL_Years" runat="server"
ConnectionString="<%$ ConnectionStrings:NIL_HOL DBConnectionString %>"
SelectCommand="SELECT DISTINCT YEAR(NonWorkingDays.HolDate) AS PubHolYears, CONVERT (varchar, YEAR(NonWorkingDays.HolDate)) AS PubHolYearsTxt FROM Regions INNER JOIN NonWorkingDays ON Regions.ID = NonWorkingDays.RegionID WHERE (NonWorkingDays.RegionID = @RegID) UNION SELECT 0 AS PubHolYears, 'Please Select' AS PubHolYearsTxt ORDER BY PubHolYearsTxt DESC">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList2" DefaultValue="0"
Name="RegID" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<div class="style1">


<table class="style2">
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="NIL_HOL_PUBHOL" BorderColor="#000099"
BorderStyle="Inset" BorderWidth="2px" CellPadding="4" GridLines="Horizontal"
Width="298px" DataKeyNames="RegionID,HolDate" ForeColor="#333333">
<RowStyle BackColor="#EFF3FB" BorderColor="Black" BorderStyle="Solid"
BorderWidth="2px" />
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="btnDelete" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this item?')"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RegionID"
SortExpression="RegionID" ReadOnly="True" >
<ItemStyle Font-Size="Smaller" ForeColor="White" Width="1px" />
</asp:BoundField>
<asp:BoundField DataField="HolDate" HeaderText="Date" ReadOnly="True"
SortExpression="HolDate" />
</Columns>
<FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="NIL_HOL_PUBHOL" runat="server"
ConnectionString="<%$ ConnectionStrings:NIL_HOL DBConnectionString %>"
SelectCommand="SELECT [RegionID], HolDate FROM [NonWorkingDays] WHERE ((YEAR([HolDate]) = @HolDate) AND ([RegionID] = @RegionID)) ORDER BY convert(datetime,[HolDate])"
DeleteCommand="DELETE FROM [NonWorkingDays] WHERE [RegionID] = @original_RegionID AND [HolDate] = @original_HolDate"

InsertCommand="INSERT INTO [NonWorkingDays] ([RegionID], [HolDate]) VALUES (@RegionID, @HolDate)"
OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" DefaultValue="0"
Name="HolDate" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DropDownList2" DefaultValue="0"
Name="RegionID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="original_RegionID" Type="Int32" />
<asp:Parameter Name="original_HolDate" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="RegionID" Type="Int32" />
<asp:Parameter Name="HolDate" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</td>
<td>


<asp:FormView ID="FormView1" runat="server" DataKeyNames="RegionID,HolDate"
DataSourceID="NIL_HOL_PUBHOL_Insert">

<InsertItemTemplate>
RegionID:
<asp:TextBox ID="RegionIDTextBox" runat="server"
Text='<%# Bind("RegionID") %>' />


HolDate:


<asp:Calendar ID="Calendar2" runat="server"
SelectedDate='<%# Bind("HolDate") %>'></asp:Calendar>
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
 <asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
<asp:Button ID="btnAddDate" runat="server" CausesValidation="False"
CommandName="New" Text="Add Date For Selected Region" />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="NIL_HOL_PUBHOL_Insert" runat="server"
ConnectionString="<%$ ConnectionStrings:NIL_HOL DBConnectionString %>"
DeleteCommand="DELETE FROM [NonWorkingDays] WHERE [RegionID] = @RegionID AND [HolDate] = @HolDate"
InsertCommand="INSERT INTO [NonWorkingDays] ([RegionID], [HolDate]) VALUES (@RegionID, @HolDate)"
SelectCommand="SELECT [RegionID], [HolDate] FROM [NonWorkingDays]">
<DeleteParameters>
<asp:Parameter Name="RegionID" Type="Int32" />
<asp:Parameter Name="HolDate" DbType="Date" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="RegionID" Type="Int32" />
<asp:Parameter Name="HolDate" DbType="Date" />
</InsertParameters>
</asp:SqlDataSource>
<asp:Button ID="btnAddDate2" runat="server" onclick="btnAddDate_Click"
Text="Add Date For " />
</td>
</tr>
</table>


</div>


<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>


</div>
</form>
  
0
Langy
4/20/2009 9:14:17 AM
📁 asp.net.getting-started
📃 91979 articles.
⭐ 4 followers.

💬 2 Replies
👁️‍🗨️ 3097 Views



HI,
YOU CAN READ MY BELOW POST. HOPE IT WILL HELP YOU.
http://shawpnendu.blogspot.com/2009/02/how-to-read-data-from-sql-server-stored.html
MARK AS ANSWER if its help you.

Shawpnendu Bikash Maloroy
http://shawpnendu.blogspot.com
0
shawpnendu
4/20/2009 9:32:09 AM

Thanks for that, that looks pretty useful.
Still back to my current issue, how do I populate my form field with the text from a combo outside of the form?
 Langy
0
Langy
4/20/2009 3:08:48 PM
Reply: