I have worked with grids before and they worked fine. Suddenly i am gettin this issue that whenever i try to add new course or edit an existing course name, the textbox value i enter returns an empty string! THerefore, a blank entry is made into the database! I have tried to debug, but i cannot understand why this is happening. Whatever i type in, turns into a blank string!
I am writing this grid in ajax tab control and ajax panel
i don't think that should cause an issue. I tried removing it from there but still same issues.
<asp:GridView ID="gvListCourses" runat="server" AllowPaging="True"
CellPadding="1" CellSpacing="2" ShowFooter="True" DataKeyNames="CourseID"
EmptyDataText="No courses available" AutoGenerateColumns="False"
Width="292px">
<AlternatingRowStyle CssClass="ProfileAlternateRow" />
<Columns>
<asp:TemplateField HeaderText="Course Name" SortExpression="Name">
<EditItemTemplate>
<asp:TextBox ID="txtCourseName" runat="server" BorderColor="#999999"
BorderStyle="Solid" BorderWidth="1px" Height="25px" Width="240px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewCourseName" runat="server"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" Height="25px"
Width="240px" MaxLength="150" Wrap="False"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lnkAddCourse" runat="server" CommandName="Add">Add...</asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True"/>
</Columns>
<FooterStyle CssClass="ProfileRow" />
<HeaderStyle CssClass="ProfileChildHeader" />
<PagerStyle CssClass="ProfileChildHeader" HorizontalAlign="Right" />
<RowStyle CssClass="ProfileRow" />
</asp:GridView>
Protected Sub gvListCourses_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvListCourses.PageIndexChanging
Try
gvListCourses.PageIndex = e.NewPageIndex
FillCourses()
Catch ex As Exception
End Try
End Sub
Protected Sub gvListCourses_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gvListCourses.RowCancelingEdit
gvListCourses.EditIndex = -1
FillCourses()
End Sub
Protected Sub gvListCourses_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvListCourses.RowCommand
Try
If e.CommandName.Equals("Add") Then
Dim txtCname As TextBox = CType(gvListCourses.FooterRow.FindControl("txtNewCourseName"), TextBox)
If Not txtCname Is Nothing Then
Dim akkad As New InstituteDefaults
If akkad.AddCourse(txtCname.Text) > 0 Then
FillCourses()
End If
End If
End If
Catch ex As Exception
End Try
End Sub
Protected Sub gvListCourses_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvListCourses.RowDeleting
Try
Dim Akkad As New InstituteDefaults
If Akkad.DeleteCourse(gvListCourses.DataKeys(e.RowIndex).Values(0)) = True Then
FillCourses()
End If
Catch ex As Exception
End Try
End Sub
Protected Sub gvListCourses_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvListCourses.RowEditing
Try
gvListCourses.EditIndex = e.NewEditIndex
FillCourses()
Catch ex As Exception
End Try
End Sub
Protected Sub gvListCourses_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvListCourses.RowUpdating
Try
Dim akkad As New InstituteDefaults
Dim txtCName As TextBox = CType(gvListCourses.Rows(e.RowIndex).FindControl("txtCourseName"), TextBox)
If Not txtCName Is Nothing Then
If akkad.AddCourse(txtCName.Text, 0, gvListCourses.DataKeys(e.RowIndex).Values(0)) = True Then
gvListCourses.EditIndex = -1
FillCourses()
End If
End If
Catch ex As Exception
End Try
End Sub