Hi AnandM, thanks for the code. I've already applied the code given
and it's successful when I save the form.But I have another issue.
When I click the edit link in gridview, the panel is automatically close and the default panel
panel which is the first panel is open----wrong. Supposedly, the panel will stay.
Actually I have 2 forms which is add and edit:
<div class="HeaderContent"> STUDENT INFORMATION - CAREER PROGRESS</div>
<div>
<table width="95%" align="center" border="0" cellspacing="3" cellpadding="3">
<tr>
<td align="center">
<br />
<table width="95%" border="0" cellpadding="2" cellspacing="2">
<tr valign="top">
<td width="18%">Student Name</td>
<td>: <asp:Label ID="lblCPGname" runat="server" Width="200"></asp:Label></td>
<td width="18%">Scholarship</td>
<td>: <asp:Label ID="lblCPGScholarship" runat="server" Width="200"></asp:Label></td>
</tr>
<tr valign="top">
<td>IC NO</td>
<td>: <asp:Label ID="lblCPGicno" runat="server" Width="200"></asp:Label></td>
<td>Intake</td>
<td>: <asp:Label ID="lblCPGintake" runat="server" Width="200"></asp:Label></td>
</tr>
</table>
<br />
</td>
</tr>
<asp:SqlDataSource ID="sqlDataSourceSBondStatus" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM ServiceBondStatus ORDER BY SBondStatus ASC"></asp:SqlDataSource>
<!------------Add Career Progress------------------------------------------------------------>
<asp:Panel ID="PanelAddCareerPro" runat="server" Visible="true">
<tr>
<td class="bar" align="center">
<b>CAREER PROGRESS DETAILS</b>
</td>
</tr>
<tr>
<td align="center">
<br />
<table width="95%" border="0" cellpadding="2" cellspacing="2">
<tr valign="top">
<td width="16%">Company Name:</td>
<td colspan="3"><asp:TextBox ID="txtCPcompName" runat="server" Width="96%" Height="23"/></td>
</tr>
<tr valign="top">
<td>Company Adress:</td>
<td colspan="3"><asp:TextBox ID="txtCPcompAddr" runat="server" Width="96%" TextMode="MultiLine"/></td>
</tr>
<tr valign="top">
<td width="16%">Date Joined:</td>
<td width="28%"><asp:TextBox ID="txtCpDateJoin" runat="server" Width="220px" /></td>
<td width="16%">Last Working Date:</td>
<td width="27%"><asp:TextBox ID="txtcCpLWD" runat="server" Width="220px" /></td>
</tr>
<tr valign="top">
<td width="16%">Service Bond Status:</td>
<td><asp:DropDownList ID="ddlCPsbs" DataSourceID="sqlDataSourceSBondStatus" DataTextField="SBondStatus" DataValueField="SBondStatusID" AppendDataBoundItems="true" runat="server" Font-Strikeout="False" Height="23" Width="220px">
<asp:ListItem Value="">SELECT</asp:ListItem>
</asp:DropDownList>
</td>
<td width="16%">Supposedly Last date of Service:</td>
<td><asp:TextBox ID="txtLastDate" runat="server" Width="220px" Height="23"/></td>
</tr>
<tr valign="top">
<td>Position:</td>
<td><asp:TextBox ID="txtCpPosition" runat="server" Width="220px" Height="23"/></td>
<td>Actual Period Serve (day):</td>
<td><asp:TextBox ID="txtCpPeriodServe" runat="server" Width="220px" Height="23"/></td>
</tr>
<tr valign="top">
<%-- <td>Contractual Bond (3/5 years):</td>
<td><asp:DropDownList ID="ddlContractualBond" DataSourceID="sqlDataSourceContractualBond" DataTextField="SBondStatus" DataValueField="SBondStatusID" AppendDataBoundItems="true" runat="server" Font-Strikeout="False" Height="23" Width="150px">
<asp:ListItem Value="">SELECT</asp:ListItem>
</asp:DropDownList>
</td>--%>
<td>Balance Contractual Bond:</td>
<td><asp:TextBox ID="txtBalContrBond" runat="server" Width="220px" Height="23"/></td>
</tr>
<tr valign="top">
<td>Total Scholarship Amount:</td>
<td><asp:TextBox ID="txtSchoolAmount" runat="server" Width="220px" Height="23"/></td>
<td> </td>
<td> </td>
</tr>
<tr valign="top">
<td>Remarks: </td>
<td colspan="3"><asp:TextBox ID="txtCpRemarks" runat="server" Width="96%" TextMode="MultiLine" />
</tr>
</table>
<br />
</td>
</tr>
<tr>
<td align="center">
<br />
<asp:Button ID="btnSaveCP" runat="server" Text="Save" OnClick="btnSaveCP_Click" ValidationGroup="ValidateClick" OnClientClick="return Validate()" />
<asp:Button ID="btnCancelCP" runat="server" Text="Cancel" OnClick="btnCancelCP_Click" />
<br /><br /><br />
</td>
</tr>
</asp:Panel>
<!------------Edit Career Progress------------------------------------------------------------>
<asp:Panel ID="PanelEditCareerPro" runat="server" Visible="true">
<tr>
<td class="bar" align="center">
<b>CAREER PROGRESS DETAILS</b>
</td>
</tr>
<tr>
<td align="center">
<br />
<table width="95%" border="0" cellpadding="2" cellspacing="2">
<tr valign="top">
<td width="16%">Company Name:</td>
<td colspan="3"><asp:TextBox ID="txtCPcompName2" runat="server" Width="96%" Height="23"/></td>
</tr>
<tr valign="top">
<td>Company Adress:</td>
<td colspan="3"><asp:TextBox ID="txtCPcompAddr2" runat="server" Width="96%" TextMode="MultiLine"/></td>
</tr>
<tr valign="top">
<td width="16%">Date Joined:</td>
<td width="28%"><asp:TextBox ID="txtCpDateJoin2" runat="server" Width="220px" /></td>
<td width="16%">Last Working Date:</td>
<td width="27%"><asp:TextBox ID="txtcCpLWD2" runat="server" Width="220px" /></td>
</tr>
<tr valign="top">
<td width="16%">Service Bond Status:</td>
<td><asp:DropDownList ID="ddlCPsbs2" DataSourceID="sqlDataSourceSBondStatus" DataTextField="SBondStatus" DataValueField="SBondStatusID" AppendDataBoundItems="true" runat="server" Font-Strikeout="False" Height="23" Width="220px">
<asp:ListItem Value="">SELECT</asp:ListItem>
</asp:DropDownList>
</td>
<td width="16%">Supposedly Last date of Service:</td>
<td><asp:TextBox ID="txtLastDate2" runat="server" Width="220px" Height="23"/></td>
</tr>
<tr valign="top">
<td>Position:</td>
<td><asp:TextBox ID="txtCpPosition2" runat="server" Width="220px" Height="23"/></td>
<td>Actual Period Serve (day):</td>
<td><asp:TextBox ID="txtCpPeriodServe2" runat="server" Width="220px" Height="23"/></td>
</tr>
<tr valign="top">
<%-- <td>Contractual Bond (3/5 years):</td>
<td><asp:DropDownList ID="ddlContractualBond2" DataSourceID="sqlDataSourceContractualBond" DataTextField="SBondStatus" DataValueField="SBondStatusID" AppendDataBoundItems="true" runat="server" Font-Strikeout="False" Height="23" Width="150px">
<asp:ListItem Value="">SELECT</asp:ListItem>
</asp:DropDownList>
</td>--%>
<td>Balance Contractual Bond:</td>
<td><asp:TextBox ID="txtBalContrBond2" runat="server" Width="220px" Height="23"/></td>
</tr>
<tr valign="top">
<td>Total Scholarship Amount:</td>
<td><asp:TextBox ID="txtSchoolAmount2" runat="server" Width="220px" Height="23"/></td>
<td> </td>
<td> </td>
</tr>
<tr valign="top">
<td>Remarks: </td>
<td colspan="3"><asp:TextBox ID="txtCpRemarks2" runat="server" Width="96%" TextMode="MultiLine" />
</tr>
</table>
<br />
</td>
</tr>
<tr>
<td align="center">
<br />
<asp:Button ID="btnUpdatecp" runat="server" Text="Update" OnClick="btnUpdateCP_Click" ValidationGroup="ValidateClick" OnClientClick="return Validate()" />
<asp:Button ID="btncancp" runat="server" Text="Cancel" OnClick="btnCancelCP_Click" />
<br /><br /><br />
</td>
</tr>
</asp:Panel>
<tr>
<td class="bar" align="center" width="90%">
<b>LIST OF CAREER PROGRESS</b>
</td>
</tr>
<tr>
<td align="center">
<table width="95%" border="0" cellpadding="2" cellspacing="2" >
<asp:SqlDataSource ID="SqlDataSourceCP" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"></asp:SqlDataSource>
<asp:GridView ID="gvCareerProgress" DataKeyNames="CpID" runat="server" PageSize="5" DataSourceID="SqlDataSourceCP" CssClass="GridViewStyle" EmptyDataRowStyle-HorizontalAlign="Center" EmptyDataRowStyle-Height="45px" EmptyDataText="No Records Found"
OnRowDataBound="GridViewCP_RowDataBound"
ShowHeader="true"
ShowHeaderWhenEmpty="true"
AutoGenerateColumns="False"
Width="100%">
<RowStyle CssClass="RowStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<EditRowStyle CssClass="EditRowStyle" />
<Columns>
<asp:TemplateField HeaderText="No"><ItemStyle width ="5%" VerticalAlign="Top" HorizontalAlign="center" />
<ItemTemplate><%# Container.DataItemIndex + 1 %></ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CpCompName" HeaderText="Company" SortExpression="CpCompName" ItemStyle-Width="30%" ItemStyle-HorizontalAlign="Left" />
<asp:TemplateField HeaderText="Date Joined"><ItemStyle width ="15%" VerticalAlign="Top" HorizontalAlign="center" />
<ItemTemplate><asp:Label ID="lbldateJoin" runat="server" Text='<%#Bind("CpDateJoined","{0:dd/MM/yyyy}") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CpSBS" HeaderText="Service Bond Status" SortExpression="CpSBS" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20%" />
<asp:BoundField DataField="CpPosition" HeaderText="Position" SortExpression="CpPosition" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="15%" />
<asp:TemplateField HeaderText="Action" Visible="true"><ItemStyle width ="10%" VerticalAlign="Top" HorizontalAlign="center"/>
<ItemTemplate>
<asp:Label ID="lblcpID" runat="server" Text='<%# Eval("CpID") %>' Visible="false"/>
<asp:Label ID="lblStudentID" runat="server" Text='<%# Eval("StudentID") %>' Visible="false"/>
<asp:Hyperlink ID="lnkcpEdit" runat="server" ></asp:Hyperlink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</table>
</table>
</div>
When I use this below code to edit, it will goes wrong like I mention above.
protected void GridViewCP_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string CpID = ((Label)e.Row.FindControl("lblcpID")).Text;
string StudentID = ((Label)e.Row.FindControl("lblStudentID")).Text;
e.Row.Cells[5].Visible = true;
e.Row.Cells[5].Text = "Edit";
HyperLink cp = new HyperLink();
cp.Text = e.Row.Cells[5].Text;
cp.NavigateUrl = "informationEdit.aspx?StudentID=" + StudentID + "&CpID="+ CpID;
e.Row.Cells[5].Controls.Add(cp);
}
}
Do I need to add other panel ID in javascript or put another Hiddenfield?