Cannot get/use ControlParameter from GridView in a TemplateField SELECT statement - asp.net

I have a simple GridView (with an ID of 'GridViewAttribs') which displays some values from a database.
Within my GridViewAttribs I wish to have a (nested?) ListView but for some reason I cannot use the asp:ControlParameter ControlID="GridViewAttribs" PropertyName as no results are returned in my (nested) ListView.
If I do NOT use the ControlParameter and hardcode my SELECT statement for the ListView, everything works as expected.
Here's my code:
<asp:SqlDataSource ID="SqlDataSourceAttribHeadings" runat="server"
ConnectionString="<%$ ConnectionStrings:customer_support_devConnectionString %>"
ProviderName="<%$ ConnectionStrings:customer_support_devConnectionString.ProviderName %>"
SelectCommand="SELECT equipment_attrib_heading_id, equipment_model_id, equipment_attrib_name FROM equipment_new_attrib_headings WHERE (equipment_model_id = #equipment_model_id) AND (equipment_attrib_heading_deleted = 0) ORDER BY equipment_attrib_name">
<SelectParameters>
<asp:SessionParameter DefaultValue="" Name="equipment_model_id"
SessionField="EquipmentModelID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridViewAttribs" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="equipment_attrib_heading_id"
DataSourceID="SqlDataSourceAttribHeadings" ForeColor="#333333" GridLines="None"
style="margin-right: 0px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="equipment_attrib_heading_id"
HeaderText="equipment_attrib_heading_id" ReadOnly="True"
SortExpression="equipment_attrib_heading_id" />
<asp:BoundField DataField="equipment_model_id" HeaderText="equipment_model_id"
SortExpression="equipment_model_id" />
<asp:BoundField DataField="equipment_attrib_name"
HeaderText="equipment_attrib_name" SortExpression="equipment_attrib_name" />
<asp:TemplateField HeaderText="equipment_attrib_value_details" SortExpression="equipment_attrib_value_details">
<ItemTemplate>
<asp:SqlDataSource ID="SqlDataSourceAttribValues" runat="server"
ConnectionString="<%$ ConnectionStrings:customer_support_devConnectionString %>"
ProviderName="<%$ ConnectionStrings:customer_support_devConnectionString.ProviderName %>"
SelectCommand="SELECT [equipment_attrib_value_details] FROM [equipment_new_attrib_values] WHERE (equipment_attrib_heading_id = #head_id) AND (equipment_id = #equipment_id) AND (equipment_attrib_value_deleted = 0)">
<SelectParameters>
<asp:QueryStringParameter Name="equipment_id" QueryStringField="id"
Type="Int32" />
<asp:ControlParameter ControlID="GridViewAttribs"
Name="head_id" PropertyName="SelectedDataKey.Values[equipment_attrib_heading_id]" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:ListView ID="ListViewAttribValues" runat="server"
DataSourceID="SqlDataSourceAttribValues">
<EmptyDataTemplate>
<table runat="server" style="">
<tr><td>No data was returned.</td></tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="">
<td><asp:Label ID="equipment_attrib_value_detailsLabel" runat="server" Text='<%# Eval("equipment_attrib_value_details") %>' /></td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The GridView displays all columns fine except the "equipment_attrib_value_details" column where I get "No data was returned."
However, if I take out the asp:ControlParameter which calls upon #head_id and use this hardcoded SELECT statement then I see the correct (albeit hardcoded) values:
SelectCommand="SELECT [equipment_attrib_value_details] FROM [equipment_new_attrib_values] WHERE (equipment_attrib_heading_id = 3) AND (equipment_id = #equipment_id) AND (equipment_attrib_value_deleted = 0)">
Therefore, for some reason, it would appear that the GridViewAttribs value of "equipment_attrib_heading_id" is not being passed to / picked up by the nested asp:ControlParameter
On the off chance, I've also tried replacing:
PropertyName="SelectedDataKey.Values[equipment_attrib_heading_id]"
With:
PropertyName="SelectedValue"
But this didn't resolve the issue either, still not data was returned.
If it helps, I'm using Visual Studio 2010 with ASP.NET4 (vb).

What you could try is using a hidden field and use that control for the controlparameter
<asp:TemplateField HeaderText="equipment_attrib_value_details" SortExpression="equipment_attrib_value_details">
<ItemTemplate>
<asp:HiddenField runat="server" ID="heading_id" Value='<%# Eval("equipment_attrib_heading_id") %>' />
<asp:SqlDataSource ID="SqlDataSourceAttribValues" runat="server"
ConnectionString="<%$ ConnectionStrings:customer_support_devConnectionString %>"
ProviderName="<%$ ConnectionStrings:customer_support_devConnectionString.ProviderName %>"
SelectCommand="SELECT [equipment_attrib_value_details] FROM [equipment_new_attrib_values] WHERE (equipment_attrib_heading_id = #head_id) AND (equipment_id = #equipment_id) AND (equipment_attrib_value_deleted = 0)">
<SelectParameters>
<asp:QueryStringParameter Name="equipment_id" QueryStringField="id" Type="Int32" />
<asp:ControlParameter ControlID="heading_id" Name="head_id" PropertyName="Value" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:ListView ID="ListViewAttribValues" runat="server"
DataSourceID="SqlDataSourceAttribValues">
<EmptyDataTemplate>
<table id="Table2" runat="server" style="">
<tr><td>No data was returned.</td></tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="">
<td><asp:Label ID="equipment_attrib_value_detailsLabel" runat="server" Text='<%# Eval("equipment_attrib_value_details") %>' /></td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
</ItemTemplate>
</asp:TemplateField>

This only works (it seems) if the HiddenField is inside the same ItemTemplate. If the DataSource is somewhere outside the TemplateField, in cases where you want to data-populate a control that is say on another column or field of the GridView, then the HiddenField will not work, as it's technically hidden.
The way to overcome this is in code-behind. Here is how I do it...
I have a TemplateField that is referring to #StudentID, which is actually a HiddenField in another TemplateField.
<asp:TemplateField HeaderText="Currently<br/>Tracking<br/>(past weeks)">
<ItemTemplate>
<asp:CheckBoxList ID="listWeeksTracking" runat="server" DataSourceID="sdsTETpastWeeks" DataTextField="WeekNo" DataValueField="WeekNo"
OnDataBound="listWeeksTracking_DataBound" OnDataBinding="listWeeksTracking_DataBinding"></asp:CheckBoxList>
<br />
<asp:SqlDataSource ID="sdsTETpastWeeks" runat="server" ConnectionString="<%$ ConnectionStrings:ATCNTV1ConnectionString %>"
SelectCommand="SELECT tb.WeekNo, ISNULL((SELECT TOP 1 ts.ETRTWtracking FROM tblTETMeetingStudent AS ts INNER JOIN tblTETMeeting AS tm ON tm.TETmeetingID = ts.TETmeetingID AND tm.WeekNo = tb.WeekNo WHERE ts.StudentID = #StudentID),0) AS Tracking FROM tblTETInstructionalTrainingBlocks AS tb WHERE tb.WeekNo <= #WeekNo AND tb.Active = 1 AND tb.YearNum = YEAR(#TETdate) ORDER BY tb.WeekNo">
<SelectParameters>
<asp:Parameter Name="StudentID" Type="string" />
<asp:ControlParameter ControlID="ddlWeekNo" Name="WeekNo" PropertyName="SelectedValue" Type="int16" />
<asp:ControlParameter ControlID="lblTETdate" Name="TETdate" Type="DateTime" />
</SelectParameters>
</asp:SqlDataSource>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Wrap="False" />
</asp:TemplateField>
So I define the #StudentID parameter as simple a parameter, and not a ControlParameter, is it won't be able to pick up the hiddenfield elsewhere in my GridView.
In code-behind (C#), I trap the Selecting event via the DataBinding.
And in there I specifically look for the row in relation to the control I've just populated (or about to), and then I look for the HiddenField.
protected void listWeeksTracking_DataBinding(object sender, EventArgs e)
{
//set the parameter for the StudentID here as using hiddenfields does not work directly in asp.net, as they are hidden!
CheckBoxList cbl1 = (CheckBoxList)sender;
GridViewRow gvRow = (GridViewRow)cbl1.NamingContainer;
if (gvRow != null)
{
SqlDataSource sdsTETpastWeeks = (SqlDataSource)gvRow.FindControl("sdsTETpastWeeks");
HiddenField hfStudentID = (HiddenField)gvRow.FindControl("hfStudentID");
if (hfStudentID != null) sdsTETpastWeeks.SelectParameters["StudentID"].DefaultValue = hfStudentID.Value.ToString();
}
}
Voila!

Related

Server Error in '/' Application. A ControlID must be specified in ControlParameter 'Product_Name'

I am new here and a beginner with APS and VB, I do have SQL experience. the problem I am having is I am trying to select two values in a VB aspx page.
one is a text box which can be types into, the other is a value which is selected from a drop downlist that looks as a table in my SQL database.
I want both values once entered and selected to be entered as a new row into another table of the same database, but I am getting the following error. and its driving me round in circles.
A ControlID must be specified in ControlParameter 'Product_Name'.
my code is as below, I suspect it is something simple that I am missing but I cannot see it for looking, can anyone help please?
<table style="width:100%;">
<tr>
<td>
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Insert">
<InsertItemTemplate>
Product_Name:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="Product_Name" DataValueField="Product_Name">
</asp:DropDownList>
<ItemTemplate>
Product_Description:
<asp:TextBox ID="Product_DescriptionTextBox" runat="server" Text='<%# Bind("Product_Description") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Incident_TrackerConnectionString %>" InsertCommand="INSERT INTO [Incidents] ( [I_Product_Name], [I_Product_Description]) VALUES ( #Product_Name, #Product_Description)">
<InsertParameters>
<asp:ControlParameter Name="Product_Name" Type="String" />
<asp:Parameter Name="Product_Description" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Incident_TrackerConnectionString %>" SelectCommand="select Product_Name from dbo.products"></asp:SqlDataSource>
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style2"></td>
<td class="auto-style2"></td>
</tr>
<tr>
<td class="auto-style1"> </td>
<td class="auto-style1"></td>
<td class="auto-style1"></td>
</tr>
</table>
<br />
<br />
<br />
Thanks Kevin
You nee to specify the ControlID & PropertyName like this:-
<InsertParameters>
<asp:ControlParameter Name="Product_Name" ControlID="DropDownList1"
PropertyName="SelectedValue" />
</InsertParameters>
Edit:-
Okay, since you are using FormView, you need to specify it like this:-
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource2" DataTextField="Product_Name"
DataValueField="Product_Name" SelectedValue=<%# Bind('Product_Name') %>>
</asp:DropDownList>
Then , bind the InsertParameters as:-
<InsertParameters>
<asp:Parameter Name="Product_Name" Type="String" />
<asp:Parameter Name="Product_Description" Type="String" />
</InsertParameters>

Cannot Find Control ID in ControlParameter

I am trying to insert values from a textbox but I get an error that it cannot find the controlid in the controlparameter. The TextBox is inside a formview, which is inside a listview. The SqlDataSource is outside the ListView.
My InsertButton_Click Method
protected void InsertButton_Click(object sender, EventArgs e)
{
var ctrl = (Control)sender;
var formview = (FormView)ctrl.NamingContainer;
formview.ChangeMode(FormViewMode.Insert);
SectionListView.DataSource = SectionDataSource;
SectionListView.DataBind();
}
The InsertItem Template
<InsertItemTemplate>
<tr style="">
<td>
<div style="font-size: .8em;">
<asp:FormView ID="SectionFormView" runat="server" DataKeyNames="SectionItemID" DataSourceID="SectionDataSource">
<ItemTemplate>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" OnClick="InsertButton_Click" Font-Size="1.2em" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" Font-Size="1.2em" />
<asp:Label ID="SectionItemLabel" runat="server" Text="SectionItem" Font-Bold="true" Font-Size="1.2em" />
<asp:TextBox ID="SectionItemTextBox" runat="server" />
<asp:Label ID="SectionItemSubLabel" runat="server" Text="SectionItem Label" Font-Bold="true" Font-Size="1.2em" />
<asp:TextBox ID="SectionItemLabelTextBox" runat="server"/>
</ItemTemplate>
</asp:FormView>
</div>
</td>
</tr>
</InsertItemTemplate>
My SqlDataSource
<asp:SqlDataSource ID="SectionDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ORHP_Dev03182014ConnectionString %>" SelectCommand="SELECT DISTINCT SectionItem,SectionItemLabel,SectionItemID FROM Core.SectionItem_Lkup"
InsertCommand="INSERT INTO Core.SectionItem_Lkup(SectionItem, SectionItemLabel) VALUES (#SectionItem, #SectionItemLabel)">
<InsertParameters>
<asp:ControlParameter ControlID="SectionItemTextBox" Name="SectionItem" PropertyName="Text" />
<asp:ControlParameter ControlID="SectionItemLabelTextBox" Name="SectionItemLabel" PropertyName="Text" />
</InsertParameters>
</asp:SqlDataSource>
When you want to use the child controls as control parameters, you need to use the qualified id as control id. Try changing the SQL data source as below
<asp:SqlDataSource ID="SectionDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ORHP_Dev03182014ConnectionString %>" SelectCommand="SELECT DISTINCT SectionItem,SectionItemLabel,SectionItemID FROM Core.SectionItem_Lkup"
InsertCommand="INSERT INTO Core.SectionItem_Lkup(SectionItem, SectionItemLabel) VALUES (#SectionItem, #SectionItemLabel)">
<InsertParameters>
<asp:ControlParameter ControlID="SectionFormView$SectionItemTextBox" Name="SectionItem" PropertyName="Text" />
<asp:ControlParameter ControlID="SectionFormView$SectionItemLabelTextBox" Name="SectionItemLabel" PropertyName="Text" />
</InsertParameters>
</asp:SqlDataSource>

WhereParameter is not working for dropdownlist

My Table structure
Courses
Id
Description
Subjects
Id
Description
Courses (Relation to Courses table).
My code as follows
td>
<asp:DropDownList ID="ddlCourses" runat="server" DataSourceID="LinqCourses"
DataTextField="Description" DataValueField="Id"/>
<asp:LinqDataSource ID="LinqCourses" runat="server"
ContextTypeName= "DataAccess.SchoolStudyDataContext" Select="new (Description, Id)"
TableName="Courses" />
</td>
<td align="left" valign="top" class="style5" style="width: 124px">
<asp:DropDownList ID="ddlSubjects" runat="server" DataSourceID="LinqSubjects"
DataTextField="Description" DataValueField="Id"/>
<asp:LinqDataSource ID="LinqSubjects" runat="server"
ContextTypeName= "DataAccess.SchoolStudyDataContext" Select="new (Description,Courses,Id)"
TableName="Subjects" Where="Courses == #Id" />
<WhereParameters>
asp:ControlParameter ControlID="ddlCourses" Name="Id"
PropertyName="SelectedValue" Type="Int32" />
</WherePrameters>
<asp:DropDownList ID="ddlCourses" runat="server" DataSourceID="SqlDataSource1"
DataTextField="Description" DataValueField="Id"/>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>"
SelectCommand="SELECT [Description],[Courses],[Id] FROM [table_name] WHERE ([Courses ] = #Courses ) ">
<SelectParameters>
<asp:Parameter Name="Courses" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
This is not a exact answer but this might help i guess
Your Where Property is wrong. Change this (==):
Where="Courses == #Id" />
To this (=):
Where="Courses = #Id" />
Source: MSDN

How to access a value which is associated with a dropdownlist item?

This is my dropdown list code........
<td valign="top" align="center">
<asp:DropDownList ID="StudentNameDropDownList" runat="server" Width="150px"
DataSourceID="SqlDataSource2" DataTextField="StudentName"
DataValueField="StudentName" AutoPostBack="True">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:dbbilling2.0ConnectionString3 %>"
SelectCommand="SELECT [StudentID], [StudentName] FROM [tblStudentInfo] WHERE ([Class] = #Class)">
<SelectParameters>
<asp:ControlParameter ControlID="ClassDropDownList" Name="Class"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<br />
Now I want to access the Student ID field in my code behind file..How can i achieve this?? What syntax i must use[like dropdownlist.selecteditem] ??
First of all in your DropDownList asp component you must set the property DataValueField="StudentID", then in your code behind you can get the Id of the selected student by writing : StudentNameDropDownList.SelectedValue
For Id You can try this code
StudentNameDropDownList.SelectedValue

How to generate checkbox for every field in database using GridView

I have limited knowledge on VB coding. I am now creating a system which allow customer to select exhibition event and booth number they want and next reserved which day they want to rent.
By default, in GridView control can add checkbox Field but it only generate 1 checkbox for 1 row of data.
As state in the title, I have no idea how to generate the checkboxes for every field in database call D1,D2,D3,D4,D5,D6 and D7, each carry value 0 by default.
Now I want every single field have a checkbox to allow customer select which day they want to reserve and retrieve their checked value to stole into corresponding D1-D7 field, checked value will update value 0 to 1.
Next, how should I coding to store the checked value into database? in default.aspx or default.aspx.vb?
Or any other suggestion to generate checkbox instead of using gridview?
The default view using GridView
What I want
My coding:
<%# Page Language="VB" MasterPageFile="~/MasterPageMember.master" AutoEventWireup="false" CodeFile="member_view_event_list.aspx.vb" Inherits="member_view_event_list" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.style8
{
width: 46px;
}
.style9
{
}
.style10
{
width: 86px;
}
</style>
</asp:Content>
<asp:Content ID="ContentPlaceHolder2" runat="server"
contentplaceholderid="ContentPlaceHolder2">
<table width="80%">
<tr><td class="style10"> </td><td class="style8"> </td><td> </td></tr>
<tr><td class="style10">
<asp:Label ID="Label1" runat="server" Text="Select Event:"></asp:Label>
</td><td class="style8">
<asp:DropDownList ID="ddlEventList" runat="server"
DataSourceID="SqlDataSourceEvent" DataTextField="eventTitle"
DataValueField="eventID" AutoPostBack="True" Width="200">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceEvent" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT DISTINCT [eventTitle], [eventID] FROM [booth_eventinfo]">
</asp:SqlDataSource>
</td><td>
</td></tr>
<tr><td class="style10">
<asp:Label ID="Label2" runat="server" Text="Select Booth:"></asp:Label>
</td><td class="style8">
<asp:DropDownList ID="ddlBoothList" runat="server"
DataSourceID="SqlDataSourceBooth" DataTextField="boothAlias"
DataValueField="boothID" AutoPostBack="True" Width="200">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceBooth" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT [boothAlias], [boothID] FROM [booth_eventinfo] WHERE ([eventID] = #eventID)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlEventList" Name="eventID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td><td>
</td></tr>
<tr><td class="style10">
</td><td class="style8">
</td><td>
</td></tr>
<tr><td class="style9" colspan="3">
<asp:GridView ID="GridViewDay" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSourceDay" ForeColor="#333333"
GridLines="None">
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="D1" HeaderText="Day1" SortExpression="D1" />
<asp:BoundField DataField="D2" HeaderText="Day2" SortExpression="D2" />
<asp:BoundField DataField="D3" HeaderText="Day3" SortExpression="D3" />
<asp:BoundField DataField="D4" HeaderText="Day4" SortExpression="D4" />
<asp:BoundField DataField="D5" HeaderText="Day5" SortExpression="D5" />
<asp:BoundField DataField="D6" HeaderText="Day6" SortExpression="D6" />
<asp:BoundField DataField="D7" HeaderText="Day7" SortExpression="D7" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceDay" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT [D1], [D7], [D6], [D5], [D4], [D3], [D2] FROM [booth_eventinfo] WHERE ([boothID] = #boothID)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlBoothList" Name="boothID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td></tr>
<tr><td class="style10">
</td><td class="style8">
<asp:CheckBox ID="CheckBox1" runat="server" />
</td><td>
</td></tr>
</table>
</asp:Content>
You need to change your 'BoundField' to a 'TemplateField' for each CheckBox control you desire. The code example below shows you how to do this. Note the binding expression syntax for your DataField value:
<asp:TemplateField HeaderText="Day1" SortExpression="D1" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("D1") %>' />
</ItemTemplate>
</asp:TemplateField>
This may help you out. Instead of using a grid view you can use a asp:CheckBoxList, if the requirement is to only place checkboxes for the seven days. Once the list is created, you can style it horizontally using css so that it adheres to the appearance as shown in the image. This link gives a preview of a checkboxlist.
For the second part of the question, you can save it in default.aspx.vb during the final submit.
In case you want to use a gridview, then you would have to add seven templated columns and bind it to the data source.

Resources