DetailsView update - not returning new values - asp.net

After editing some fields, clicking on Update doesn't show the new values. I have tried two ways to retrieve the new values as you can see from this shortened version of the ItemUpdating event (and both return the old ones) :-
Protected Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles DetailsView1.ItemUpdating
Dim txtPassword As TextBox = CType(DetailsView1.Rows(1).Cells(1).FindControl("txtPassword"), TextBox)
Struct_Student.password = txtPassword.Text
Dim PasswordValue As String = e.NewValues("password").ToString()
Struct_Student.password = PasswordValue
End Sub
Here is a shortened version of the aspx :-
<asp:Content ID="Content1" ContentPlaceHolderID="cpMainContent" Runat="Server">
<div id="Controls">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DetailsView ID="DetailsView1"
runat="server"
AutoGenerateRows="False"
DataKeyNames="student_id" DataSourceID="SqlDataSource1"
ForeColor="Blue"
BackColor="#FFF7E6"
AutoPostBack="True"
AutoGenerateEditButton = True
AutoGenerateInsertButton = True
OnModeChanging="StudentDetailView_ModeChanging"
Height=163px
Width=327px
style="left: 400px; top: 1px; position: absolute;">
<Fields>
<asp:TemplateField
HeaderText="Password">
<EditItemTemplate>
<asp:TextBox
id="txtPassword"
Text = '<%# Bind ("password") %>'
runat = "server" />
<asp:RequiredFieldValidator
ID = "reqPassword"
ControlToValidate = "txtPassword"
Text = "(required)"
Display = "Dynamic"
runat = "server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label
id="PasswordLabel"
runat="server"
Text = '<%# Eval("password") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField
datafield="emailaddress"
headertext="Email address"
SortExpression="emailaddress"
/>
</Fields>
</asp:DetailsView>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:FCLManager %>" ProviderName="MySql.Data.MySqlClient"
SelectCommand="Select * from tblstudentinfo WHERE centre_id = #CentreID and fullname = #FullName"
<SelectParameters>
<asp:Parameter Name="CentreID" Type="Int16" DefaultValue="0" />
<asp:Parameter Name="FullName" Type="String" DefaultValue="0" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</div> <%--Controls div--%>
</asp:Content>

Related

Programmaticaly get gridview row out of edit mode

In the OnRowCommand event of a ASP.NET gridview control, how can I programmaticaly get the row OUT of edit mode?
I set the row to edit mode via a commandfield. After user clicks "Disapprove now" I want to set the row in 'regular' non-edit mode.
I now have:
<asp:TemplateField HeaderStyle-Width="100" HeaderText="Actions" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Literal ID="ltStatus" runat="server" />
<asp:LinkButton CssClass="btn-primary-green" CommandArgument="<%# Container.DataItemIndex %>" ID="btnApprove" CommandName="approve" runat="server" Text="Approve" /><br />
<asp:LinkButton CssClass="btn-primary" CommandArgument="<%# Container.DataItemIndex %>" ID="btnDelete" Visible="false" CommandName="deleteorder" runat="server" Text="Delete" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlDisApproveReason" ValidationGroup="disapprove" runat="server" >
<asp:ListItem Text="<%$Resources:disapprovereason %>" Value="0" />
<asp:ListItem Text="<%$Resources:duplicateorder %>" Value="1" />
<asp:ListItem Text="<%$Resources:testorder %>" Value="2" />
<asp:ListItem Text="<%$Resources:retourorder %>" Value="3" />
</asp:DropDownList>
<asp:RequiredFieldValidator CssClass="errortext" ID="rfvDisapprove" InitialValue="0" ValidationGroup="disapprove" ControlToValidate="ddlDisApproveReason" runat="server" ErrorMessage="<%$resources:glossary,required %>" SetFocusOnError="true" Display="Dynamic" />
<asp:LinkButton CssClass="btn-primary" ValidationGroup="disapprove" CommandArgument="<%# Container.DataItemIndex %>" ID="btnDisApprove" CommandName="disapprove" runat="server" Text="Disapprove now" />
<br />
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true" EditText="<%$Resources:disapprove %>" />
OnRowCommand Event
Protected Sub gvAllOrders_OnRowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvAllOrders.RowCommand
If e.CommandName = "disapprove" Then
index = Convert.ToInt32(e.CommandArgument)
data = gvAllOrders.DataKeys(index)
orderId = data.Values("id")
Dim clickedRow As GridViewRow = CType(CType(e.CommandSource, LinkButton).NamingContainer, GridViewRow)
Dim reason As Integer = CType(clickedRow.FindControl("ddlDisApproveReason"), DropDownList).SelectedValue
If GeneralFunctions.DisapproveOrder(False, reason, Date.Now, orderId) = 1 Then
'disaprove order
'HERE I WANT THE ROW TO GO OUT OF EDIT MODE
gvAllOrders.DataBind()
End If
End If
End Sub

Accessing Controls from another formview inside the same page

I have several forms, each with their own DDL, that I'm using inside a page. I have them in different forms because I need different data sources for each DDL. When I press the Submit button, it gives me an error that it can't find the control "ddlCategory". I assume it is because it is in a different form. Here is the markup:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"
DataSourceID="AccessDataSource1" DefaultMode="Insert" >
<InsertItemTemplate>
Select a Category:<br />
<asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="True"
DataSourceID="AccessDataSource1" DataTextField="ORG_NAME"
DataValueField="ID">
</asp:DropDownList>
</InsertItemTemplate>
</asp:FormView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT * FROM [ORGANIZATIONS]"/>
<br />
<asp:FormView ID="FormView2" runat="server" DataKeyNames="ID"
DataSourceID="AccessDataSource2" DefaultMode="Insert" >
<InsertItemTemplate>
Select an Organization:<br />
<asp:DropDownList ID="ddlOrg" runat="server"
DataSourceID="AccessDataSource2" DataTextField="SectionName"
DataValueField="ID">
</asp:DropDownList>
</InsertItemTemplate>
</asp:FormView>
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT ID,SectionName FROM ORG_SECTIONS WHERE OrgID=#OrgID ">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCategory"
PropertyName="SelectedValue"
Name="ID" Type="String"
DefaultValue="" />
</SelectParameters>
</asp:AccessDataSource>
<br />
<asp:FormView ID="FormView3" runat="server" DataKeyNames="ID"
DataSourceID="AccessDataSource3" DefaultMode="Insert" >
<InsertItemTemplate>
Select an Attorney:<br />
<asp:DropDownList ID="ddlAtty" runat="server"
DataSourceID="AccessDataSource3" DataTextField="Expr1" DataValueField="ATTY_ID">
</asp:DropDownList>
</InsertItemTemplate>
</asp:FormView>
<asp:AccessDataSource ID="AccessDataSource3" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT ATTY_ID, NAME & ' ' & INITIAL & ' ' & LASTNAME AS Expr1 FROM ATTORNEYS ORDER BY NAME & INITIAL & ' ' & LASTNAME">
</asp:AccessDataSource>
Also, if there is a way to do it inside one formview control, I'd like to know that too.
Did it this way:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT * FROM [ORGANIZATIONS]"/>
<asp:AccessDataSource ID="AccessDataSource3" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT ATTY_ID, NAME & ' ' & INITIAL & ' ' & LASTNAME AS Expr1 FROM ATTORNEYS ORDER BY NAME & INITIAL & ' ' & LASTNAME">
</asp:AccessDataSource>
<br />
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"
DataSourceID="AccessDataSource1" DefaultMode="Insert" >
<InsertItemTemplate>
Select a Category:<br />
<asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="True"
DataSourceID="AccessDataSource1" DataTextField="ORG_NAME"
DataValueField="ID">
</asp:DropDownList>
<br />
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT ID,SectionName FROM ORG_SECTIONS WHERE OrgID=#OrgID ">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCategory"
PropertyName="SelectedValue"
Name="ID" Type="String"
DefaultValue="" />
</SelectParameters>
</asp:AccessDataSource>
Select an Organization:<br />
<asp:DropDownList ID="ddlOrg" runat="server"
DataSourceID="AccessDataSource2" DataTextField="SectionName"
DataValueField="ID">
</asp:DropDownList>
<br />
Select an Attorney:<br />
<asp:DropDownList ID="ddlAtty" runat="server"
DataSourceID="AccessDataSource3" DataTextField="Expr1" DataValueField="ATTY_ID">
</asp:DropDownList>
</InsertItemTemplate>
</asp:FormView>
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="AddRec" />
And the code behind:
protected void AddRec(object sender, EventArgs e)
{
DropDownList ddlCategory = (DropDownList)FormView1.FindControl("ddlCategory");
DropDownList ddlOrg = (DropDownList)FormView1.FindControl("ddlOrg");
DropDownList ddlAtty = (DropDownList)FormView1.FindControl("ddlAtty");
string constr = #"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\webvideos.mdb;";
string cmdstr = "INSERT INTO [Org_Sec_Atty] ([OrgID], [SecID], [Atty_ID]) VALUES (?, ?, ?)";
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand com = new OleDbCommand(cmdstr, con);
con.Open();
com.Parameters.AddWithValue("#OrgID", ddlCategory.SelectedValue);
com.Parameters.AddWithValue("#SecID", ddlOrg.SelectedValue);
com.Parameters.AddWithValue("#AttyID", ddlAtty.SelectedValue);
com.ExecuteNonQuery();
con.Close();
Response.Redirect("ManageProfAffs.aspx");
}
And done.

InsertCommand into Header Template

Trying to insert three textboxes into the header of a gridview and with a button execute an "INSERT INTO" into the database.
In my online server database: idt is int, datetime is varchar, and col1,col2,col3 are numeric.
<asp:SqlDataSource
id="SqlDataSource1"
ConnectionString="<%$ ConnectionStrings:connone %>"
SelectCommand="SELECT * FROM [test];"
InsertCommand="INSERT INTO [test] [datetime],[col1],[col2],[col3] VALUES #datetime,#col1,#col2,#col3;"
runat="server">
<InsertParameters>
<asp:Parameter Name="datetime" Type="String" />
<asp:Parameter Name="col1" Type="Double" />
<asp:Parameter Name="col2" Type="Double" />
<asp:Parameter Name="col3" Type="Double" />
</InsertParameters>
</asp:SqlDataSource>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
SqlDataSource1.InsertParameters("#datetime").DefaultValue = DateTime.Now.ToString()
SqlDataSource1.InsertParameters("#col1").DefaultValue = CType(GridView1.HeaderRow.FindControl("TextBoxHeadercol1"), TextBox).Text
SqlDataSource1.InsertParameters("#col2").DefaultValue = CType(GridView1.HeaderRow.FindControl("TextBoxHeadercol2"), TextBox).Text
SqlDataSource1.InsertParameters("#col3").DefaultValue = CType(GridView1.HeaderRow.FindControl("TextBoxHeadercol3"), TextBox).Text
SqlDataSource1.Insert()
End Sub
<asp:GridView ID="GridView1"
runat="server"
DataSourceID="SqlDataSource1"
AutoGenerateColumns="False"
DataKeyNames="idt">
<Columns>
<asp:BoundField DataField="idt" HeaderText="idt" Readonly="true" SortExpression="idt" />
<asp:BoundField DataField="datetime" HeaderText="datetime" SortExpression="datetime" />
<asp:TemplateField SortExpression="col1">
<HeaderTemplate>
<asp:TextBox ID="TextBoxHeadercol1" text="col1" runat="server" MaxLength="40" />
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="col2">
<HeaderTemplate>
<asp:TextBox ID="TextBoxHeadercol2" text="col2" runat="server" MaxLength="40" />
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="col3">
<HeaderTemplate>
<asp:TextBox ID="TextBoxHeadercol3" text="col3" runat="server" MaxLength="40" />
</HeaderTemplate>
</asp:TemplateField>
</asp:GridView>
I suggest to remove "#" in InsertParameters as follows:
SqlDataSource1.InsertParameters("col1").DefaultValue =
((TextBox)GridView1.HeaderRow.FindControl("TextBoxHeadercol1")).Text;
this should work.

UpdatePanel not updating ListBox

I have an UpdatePanel containing a ListBox. Whenever I change selection on from a DropDown I want the list to get updated via an UpdatePanel. However this is not working.
This is my code so far:
Protected Sub drpDepartments_SelectedIndexChanged(sender As Object, e As EventArgs) Handles drpDepartments.SelectedIndexChanged
Dim conn As New SqlConnection("Data Source=BRIAN-PC\SQLEXPRESS;Initial Catalog=master_db;Integrated Security=True")
Dim deptComm As String = "SELECT department_id FROM departments WHERE department_name = #DepartmentName"
Dim deptSQL As New SqlCommand
Dim dr As SqlDataReader = deptSQL.ExecuteReader()
deptSQL = New SqlCommand(deptComm, conn)
deptSQL.Parameters.AddWithValue("#DepartmentName", drpDepartments.SelectedItem.Text)
dr.Read()
If dr.HasRows Then
Dim department_id As Integer = Convert.ToInt32(dr("department_id"))
Session("DepartmentID") = department_id
End If
dr.Close()
conn.Close()
ASP
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:ListBox ID="lstDeptMembers" runat="server" DataSourceID="SqlDataSource4" DataTextField="name" DataValueField="name" Height="176px" Width="204px"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpDepartments" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStringDb1 %>" SelectCommand="SELECT * FROM users u
INNER JOIN
(
Select x.user_id as userid,x.department_id,y.department_name
from user_Department x
inner join departments y
on x.department_id=y.department_id WHERE x.department_id=#parameter
)
f on u.user_id= f.userid">
<SelectParameters>
<asp:SessionParameter Name="parameter" SessionField="DepartmentID" />
</SelectParameters>
</asp:SqlDataSource>
DropDownList:
<asp:DropDownList ID="drpDepartments" runat="server" DataSourceID="SqlDataSource3" DataTextField="department_name" DataValueField="department_name">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStringDb1 %>" SelectCommand="SELECT [department_name] FROM [departments]"></asp:SqlDataSource>
Screenshot:
How can I make it that the ListBox updates whenever a new selection is clicked from the DropDown ?
EDIT: Code for the table that contains the ListBox etc.. :
<asp:DropDownList ID="drpDepartments" runat="server" DataSourceID="SqlDataSource3" DataTextField="department_name" DataValueField="department_name">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStringDb1 %>" SelectCommand="SELECT [department_name] FROM [departments]"></asp:SqlDataSource>
<br />
<br />
<table style="width:100%;">
<tr>
<td style="width: 221px">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:ListBox ID="lstDeptMembers" runat="server" DataSourceID="SqlDataSource4" DataTextField="name" DataValueField="name" Height="176px" Width="204px"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpDepartments" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStringDb1 %>" SelectCommand="SELECT * FROM users u
INNER JOIN
(
Select x.user_id as userid,x.department_id,y.department_name
from user_Department x
inner join departments y
on x.department_id=y.department_id WHERE x.department_id=#parameter
)
f on u.user_id= f.userid">
<SelectParameters>
<asp:SessionParameter Name="parameter" SessionField="DepartmentID" />
</SelectParameters>
</asp:SqlDataSource>
</td>
<td style="width: 398px">
<asp:TextBox ID="txtuserSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnSearchDeptUser" runat="server" Text="Search" />
<br />
<asp:Label ID="lblAddDeptUser" runat="server" Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td >
<asp:Button ID="btnRmvDeptMem" runat="server" Text="Remove" />
</td>
<td>
<asp:Button ID="btnAddDeptUser" runat="server" Text="Add" />
</td>
</tr>
</table>
Full code for Departments.aspx
If you want to update the UpdatePanel immediately when the user selects an item in the DropDownList you have to set it's AutoPostBack property to "True"(default is false):
<asp:DropDownList ID="drpDepartments" runat="server" DataSourceID="SqlDataSource3"
AutoPostack="True" DataTextField="department_name" DataValueField="department_name">
</asp:DropDownList>
try this...
Change this
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
with
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">

Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'

I'm creating a student evaluation form in a repeater that should submit the evaluation responses and update the SQL database, but I keep getting the error mentioned in the title. I'm coding in ASP.Net using VB.
Here's my code:
Student.aspx
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
<asp:Wizard ID="StudentEvaluationWizard" runat="server" ActiveStepIndex="0">
<WizardSteps>
<asp:WizardStep ID="WizardStep1" runat="server" Title="Course">
<asp:GridView ID="CourseView" runat="server" AutoGenerateColumns="False"
DataKeyNames="SectionID" >
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="EnrollmentID" HeaderText="EnrollmentID"
InsertVisible="False" ReadOnly="True" SortExpression="EnrollmentID" />
<asp:BoundField DataField="StudentID" HeaderText="StudentID"
SortExpression="StudentID" />
<asp:BoundField DataField="SectionID" HeaderText="SectionID"
SortExpression="SectionID" />
<asp:TemplateField ConvertEmptyStringToNull="False" HeaderText="Section" >
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Section.Course.Name") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep2" runat="server" Title="Evaluation">
<asp:Repeater ID="EvalRepeater" runat="server"
DataSourceID="EvaluationQuestions">
<HeaderTemplate><caption><asp:Label ID="EvaluationTitle" runat="server" Text='<%Eval("Evaluation.Evaluation1.") %>' /><caption></HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="QuestionID" runat="server" Text='<%# Eval("QuestionID") %>' Visible="false" />
</td>
<td>
<asp:Label ID="Questions" runat="server" Text='<%# Eval("Question1") %>' />
</td>
<td>
<%--Move outside of table to make edits--%>
<asp:RadioButtonList ID="Question" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:TextBox ID="StudentComment" runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Button ID="SubmitButton" runat="server" Text="Submit Evaluation" />
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
<asp:LinqDataSource ID="CourseSelect" runat="server" ContextTypeName="EvaluationDAL.Model.EvaluationDataDataContext"
EntityTypeName="Enrollment" TableName="Enrollments" Where="StudentID == #StudentID">
<WhereParameters>
<asp:SessionParameter DefaultValue="StudentID" Name="StudentID" SessionField="StudentID"
Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
<asp:LinqDataSource ID="EvaluationQuestions" runat="server" ContextTypeName="EvaluationDAL.Model.EvaluationDataDataContext"
EntityTypeName="" TableName="Questions"
Where="EvaluationID == Convert.ToInt32(#EvaluationID)">
<WhereParameters>
<asp:SessionParameter Name="EvaluationID" SessionField="EvaluationID"
Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
</asp:Content>
Student.aspx.vb (Submit button with the error)
Protected Sub SubmitButton_Click(sender As Object, e As System.EventArgs) Handles SubmitButton.Click
Dim sr As New StudentEvaluation
sr.SectionID = EvaluationGlobal.SectionID
sr.EvaluationDate = DateAndTime.Now
'Create a new evaluation object
Dim eval As New StudentEvaluation
For Each row As RepeaterItem In EvalRepeater.Items
'Get the question
Dim questionID As Label = CType(row.FindControl("QuestionID"), Label)
Dim question1 As Integer = Convert.ToInt32(question1)
eval.Comments = Convert.ToInt32(row.FindControl("Comments"))
'Find radio button list with the name Question and convert to radio button list
Dim rank As RadioButtonList = CType(row.FindControl("Question"), RadioButtonList)
'Get the infomation if the area is not empty
If Not String.IsNullOrWhiteSpace(rank.SelectedValue) Then
Dim ser As New StudentEvaluationResponse
ser.QuestionID = Convert.ToInt32(row.FindControl("QuestionID"))
ser.Answer = Convert.ToInt16(row.FindControl("Question"))
Dim questionRank As Integer = Convert.ToInt32(rank.SelectedValue)
Dim studentComment As TextBox = CType(row.FindControl("StudentComment"), TextBox)
Dim comment As String = studentComment.Text
eval.StudentEvaluationResponses.Add(ser)
End If
Next
If eval.StudentEvaluationResponses.Count > 0 Then
eval.Insert()
End If
End Sub
I'm completely lost on how to fix this. Any help would be awesome.
This looks wrong to start with:
Dim question1 As Integer = Convert.ToInt32(question1)
I suspect you actually mean:
Dim question1 As Integer = Convert.ToInt32(questionID.Text)
Likewise I suspect these:
ser.QuestionID = Convert.ToInt32(row.FindControl("QuestionID"))
ser.Answer = Convert.ToInt16(row.FindControl("Question"))
should use the Text property:
ser.QuestionID = Convert.ToInt32(CType(row.FindControl("QuestionID"), Label).Text)
ser.Answer = Convert.ToInt16(CType(row.FindControl("Question"), RadioButton).Text)
That way you're trying to convert the text of the control, not the control itself.

Resources