.NET ListView not populating on control selection - c#

I have a ListView in .NET that is hooked up to various CRUD methods, the select method that accepts a value doesn't seem to be working. The Data Source is supposed to be taking the value from a drop down list control, taking the selected value. when I do the configure data source method in visual studio, I select this method for my select operation:
EntReqList_byID(Int32 programID), returns List<EntranceRequirementInfo>
Then when I define parameters in the next part of the wizard, I pick control as a parameter source, with the control ID set to CertificateList, which shows the programID as the parameter from CertificateList.SelectedValue.
When I run the page, and select an item from the CertificateList, and click "Show Program", all my data is pulled except for that in the list view. My code is as follows:
The top of my page:
Please select the program credential type:
<asp:DropDownList ID="InitialCredential" runat="server" AutoPostBack="True" OnSelectedIndexChanged="InitialCredential_SelectedIndexChanged">
<asp:ListItem>[Select]</asp:ListItem>
<asp:ListItem>Certificate</asp:ListItem>
<asp:ListItem>Diploma</asp:ListItem>
<asp:ListItem>Degree</asp:ListItem>
</asp:DropDownList>
</p>
<p>
Please select a program:
<asp:DropDownList ID="CertificateList" runat="server" DataSourceID="CertificateODS" DataTextField="ProgramName" DataValueField="ProgramID" Visible="false"></asp:DropDownList>
<asp:DropDownList ID="DiplomaList" runat="server" DataSourceID="DiplomaListODS" DataTextField="ProgramName" DataValueField="ProgramID" Visible="false"></asp:DropDownList>
<asp:DropDownList ID="DegreeList" runat="server" DataSourceID="DegreeListODS" DataTextField="DegreeName" DataValueField="DegreeID" Visible="false"></asp:DropDownList>
</p>
<p>
<asp:LinkButton ID="ShowUpdateFields" runat="server" OnClick="ShowUpdateFields_Click">Show Program</asp:LinkButton>
</p>
My ListView:
<asp:ListView ID="EntReqListView" runat="server" DataSourceID="EntranceReqODS" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="ProgramIDLabel" runat="server" Text='<%# Eval("ProgramID") %>' />
</td>
<td>
<asp:Label ID="CourseIDLabel" runat="server" Text='<%# Eval("CourseID") %>' />
</td>
<td>
<asp:Label ID="CourseNameLabel" runat="server" Text='<%# Eval("CourseName") %>' />
</td>
<td>
<asp:Label ID="MarkLabel" runat="server" Text='<%# Eval("Mark") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:TextBox ID="ProgramIDTextBox" runat="server" Text='<%# Bind("ProgramID") %>' />
</td>
<td>
<asp:TextBox ID="CourseIDTextBox" runat="server" Text='<%# Bind("CourseID") %>' />
</td>
<td>
<asp:TextBox ID="CourseNameTextBox" runat="server" Text='<%# Bind("CourseName") %>' />
</td>
<td>
<asp:TextBox ID="MarkTextBox" runat="server" Text='<%# Bind("Mark") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="ProgramIDTextBox" runat="server" Text='<%# Bind("ProgramID") %>' />
</td>
<td>
<asp:TextBox ID="CourseIDTextBox" runat="server" Text='<%# Bind("CourseID") %>' />
</td>
<td>
<asp:TextBox ID="CourseNameTextBox" runat="server" Text='<%# Bind("CourseName") %>' />
</td>
<td>
<asp:TextBox ID="MarkTextBox" runat="server" Text='<%# Bind("Mark") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="ProgramIDLabel" runat="server" Text='<%# Eval("ProgramID") %>' />
</td>
<td>
<asp:Label ID="CourseIDLabel" runat="server" Text='<%# Eval("CourseID") %>' />
</td>
<td>
<asp:Label ID="CourseNameLabel" runat="server" Text='<%# Eval("CourseName") %>' />
</td>
<td>
<asp:Label ID="MarkLabel" runat="server" Text='<%# Eval("Mark") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server"></th>
<th runat="server">ProgramID</th>
<th runat="server">CourseID</th>
<th runat="server">CourseName</th>
<th runat="server">Mark</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="ProgramIDLabel" runat="server" Text='<%# Eval("ProgramID") %>' />
</td>
<td>
<asp:Label ID="CourseIDLabel" runat="server" Text='<%# Eval("CourseID") %>' />
</td>
<td>
<asp:Label ID="CourseNameLabel" runat="server" Text='<%# Eval("CourseName") %>' />
</td>
<td>
<asp:Label ID="MarkLabel" runat="server" Text='<%# Eval("Mark") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
My Code behind:
protected void InitialCredential_SelectedIndexChanged(object sender, EventArgs e)
{
//display programs DDL based on credential choice
if(InitialCredential.SelectedValue == "Certificate")
{
CertificateList.Visible = true;
DiplomaList.Visible = false;
DegreeList.Visible = false;
}
else if (InitialCredential.SelectedValue == "Diploma")
{
CertificateList.Visible = false;
DiplomaList.Visible = true;
DegreeList.Visible = false;
}
else if (InitialCredential.SelectedValue == "Degree")
{
CertificateList.Visible = false;
DiplomaList.Visible = false;
DegreeList.Visible = true;
}
else
{
CertificateList.Visible = false;
DiplomaList.Visible = false;
DegreeList.Visible = false;
}
}
protected void CredentialType_SelectedIndexChanged(object sender, EventArgs e)
{
switch (CredentialType.SelectedValue)
{
case "Diploma":
{
entrance_req.Visible = true;
degree_link.Visible = false;
degree_pathways.Visible = true;
}
break;
case "Certificate":
{
entrance_req.Visible = true;
degree_link.Visible = false;
degree_pathways.Visible = false;
}
break;
case "Degree":
{
entrance_req.Visible = false;
degree_link.Visible = true;
degree_pathways.Visible = false;
}
break;
default:
{
entrance_req.Visible = false;
degree_link.Visible = false;
degree_pathways.Visible = false;
}
break;
}
}
protected void ShowUpdateFields_Click(object sender, EventArgs e)
{
show_update_form.Visible = true;
if (InitialCredential.SelectedValue == "Certificate")
{
DiplomaCertificate certificate = new DiplomaCertificate();
PathwaysController controller = new PathwaysController();
certificate = controller.CertificateProgram_byID(int.Parse(CertificateList.SelectedValue));
ProgramName.Text = certificate.ProgramName;
CategoryList.SelectedValue = certificate.CategoryID.ToString();
CredentialType.SelectedValue = "Certificate";
ProgramLength.Text = certificate.ProgramLength;
ProgramLink.Text = certificate.ProgramLink;
Activated.Checked = certificate.Activated;
WorkOutdoors.Checked = certificate.WorkOutdoors;
ShiftWork.Checked = certificate.ShiftWork;
Travel.Checked = certificate.WorkTravel;
}
}
Is there something I am missing to make it get the programID, and populate the data?

Related

How to delete a row from GridView without affecting the Database

I am populating a Gridview using a form with the help of AJAX.
I want to add a delete button to each row and whendelet button is clicked that row should be deleted from GridView (not hidden).
Here is my aspx code:
<asp:Content ID="Content2" ContentPlaceHolderID="Nav" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<table>
<tr>
<td class="auto-style1">
<asp:Label ID="LabelFirstName" runat="server" Text="First Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBoxFirstName" runat="server" CssClass="auto-style2"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="LabelLastName" runat="server" Text="Last Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBoxLastName" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<br /><br />
<asp:Button ID="ButtonSearch" runat="server" Text="Search" CssClass="auto-style3" Width="93px" OnClick="ButtonSearch_Click" />
<br /><br />
<asp:Label ID="LabelNoRows" runat="server" Text="Sorry, we couldn't find any data with this Name." Visible="false" ForeColor="Red"></asp:Label>
<asp:Panel ID="PanelAbsenceInfo" runat="server" Visible="false">
<table>
<tr>
<td class="auto-style4">
<asp:Label ID="LabelFname" runat="server" Text="First Name:"></asp:Label>
</td>
<td>
<asp:Label ID="LabelGetFirstName" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style4">
<asp:Label ID="LabelLname" runat="server" Text="Last Name"></asp:Label>
</td>
<td>
<asp:Label ID="LabelGetLname" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style4">
<asp:Label ID="LabelEmail" runat="server" Text="Email"></asp:Label>
</td>
<td>
<asp:Label ID="LabelGetEmail" runat="server"></asp:Label>
</td>
</tr>
<asp:UpdatePanel ID="UpdatePanelInfo" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<tr>
<td class="auto-style4">
<asp:Label ID="LabelPersonal" runat="server" Text="Personal Days Approved" ></asp:Label>
</td>
<td>
<asp:Label ID="LabelGetPersonal" runat="server" ></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style4">
<asp:Label ID="LabelOther" runat="server" Text="Other Days Approved"></asp:Label>
</td>
<td>
<asp:Label ID="LabelGetOther" runat="server" ></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style4">
<asp:Label ID="LabelTotalDays" runat="server" Text="Total Days Approved" ></asp:Label>
</td>
<td>
<asp:Label ID="LabelgetTotaldays" runat="server" ></asp:Label>
</td>
</tr>
</table>
<br /><br />
<asp:GridView ID="GridViewViewAllRequests" runat="server" AutoGenerateColumns="False" DataKeyNames="id"
OnRowCommand="GridViewViewAllRequests_RowCommand">
<Columns>
<asp:BoundField DataField="scrap" Visible ="false" />
<asp:BoundField DataField="isApproved" Visible="false" />
<asp:BoundField HeaderText="Date of Absence" DataField="requestedDate" DataFormatString="{0:MM/dd/yyyy}" />
<asp:BoundField HeaderText="Rotation Period" DataField="rotationPeriod" />
<asp:BoundField HeaderText="Reason" DataField="reason" />
<asp:BoundField HeaderText="Days Missed" DataField="daysMissed" />
<asp:BoundField HeaderText="Department" DataField="departmentName" />
<asp:BoundField HeaderText="Course" DataField="courseName" />
<asp:TemplateField HeaderText="Approved/Declined">
<ItemTemplate>
<asp:Label ID="LabelApproveorDecline" runat="server" Text='<%# Eval("isApproved") == null ? "Decision not yet made." : ((bool)Eval("isApproved") ? "Approved" : "Declined") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Scrap/Undo">
<ItemTemplate>
<asp:Button ID="ScrapButton" CommandArgument='<%# Eval("id") %>' runat="server" Text="Scrap" CommandName="Scrap" Visible='<%# !(bool)Eval("scrap") %>' />
<asp:Button ID="UndoButton" CommandArgument='<%# Eval("id") %>' runat="server" Text="Undo" CommandName="Undo" Visible='<%# (bool)Eval("scrap") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<br /><br />
</asp:Content>
And here is my cs code:
public partial class AbsenceRequestMonitor : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ButtonSearch_Click(object sender, EventArgs e)
{
DoAction();
}
public Boolean ScraptheRequest(int id, bool action)
{
bool success = false;
success = DBOperation.ScrapAbsencedate(id, action);
return success;
}
protected void GridViewViewAllRequests_RowCommand(object sender, GridViewCommandEventArgs e)
{
//Determine the RowIndex of the Row whose Button was clicked.
int id = Convert.ToInt32(e.CommandArgument);
//Get the value of column from the DataKeys using the RowIndex.
// int id = Convert.ToInt32(GridViewViewAllRequests.DataKeys[rowIndex].Values[0]);
if(e.CommandName == "Scrap")
{
ScraptheRequest(id, true);
}
else if(e.CommandName == "Undo")
{
ScraptheRequest(id, false);
}
DoAction();
UpdatePanelInfo.Update();
}
public void DoAction()
{
string firstName = null;
string lastName = null;
firstName = TextBoxFirstName.Text.ToString();
lastName = TextBoxLastName.Text.ToString();
double PdCount = 0;
double OtherCount = 0;
if (firstName != null && lastName != null)
{
//gets student data from the Student Form
List<AbsenceMonitorData> l_studentAbsenceInfo = DBOperation.getStudentAbsenceInfo(firstName, lastName);
AbsenceMonitorData studentAbsenceInfo = l_studentAbsenceInfo.FirstOrDefault();
PdCount += l_studentAbsenceInfo.Where(x => x.reason == "Personal Day").Where(y => y.isApproved == true).Where(z => z.scrap == false).Select(a => a.daysMissed).Sum();
OtherCount += l_studentAbsenceInfo.Where(x => x.reason != "Personal Day").Where(y => y.isApproved == true).Where(z => z.scrap == false).Select(a => a.daysMissed).Sum();
GridViewViewAllRequests.DataSource = l_studentAbsenceInfo;
GridViewViewAllRequests.DataBind();
if (l_studentAbsenceInfo.Count > 0)
{
LabelGetPersonal.Text = PdCount.ToString();
LabelGetOther.Text = OtherCount.ToString();
LabelgetTotaldays.Text = (PdCount + OtherCount).ToString();
LabelGetFirstName.Text = studentAbsenceInfo.firstName.ToString();
LabelGetLname.Text = studentAbsenceInfo.lastname.ToString();
LabelGetEmail.Text = studentAbsenceInfo.studentEmail.ToString();
PanelAbsenceInfo.Visible = true;
LabelNoRows.Visible = false;
}
else
{
LabelNoRows.Visible = true;
}
}
}
}
Right now i was using the Scrap/Undo button which i want to replace it with a Delete button.
Also when i delete the row the count should be affected. (ie. Personal Days Approved, Other Days Approved and Total Days Approved)
The image shows that when i type the name and hit search, GridView is obtained.
I need to be able to delete rows from that gridview.
GridView

Change table row text and bgcolor on a listview value asp.net C

I have a listview and I am trying to change the text color and background color depending on the value of "callswaiting". This is written in C#.
I am trying to accomplish this:
If(Eval("availableAgents") < 1); Then
; If(Eval("callsWaiting" > 2) ,Then );
{
tblSheet.Style.Add("color", "black");
tblSheet.Style.Add("background-color", "red");
}
Else;
{
tblSheet.Style.Add("color", "black");
tblSheet.Style.Add("background-color", "orange");
}
End If;
Else;
{
tblSheet.Style.Add("color", "white");
tblSheet.Style.Add("background-color", "green");
}
End If;
Just stumped on how to update this to ASPX and C#.
My ASPX code is:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:ListView ID="ListView1" runat="server" DataSourceID="con_csq_agentDB" onitemdatabound="ListView1_ItemDataBound">
<AlternatingItemTemplate>
<tr id="MainTableRow" style="background-color: #ADADAD;">
<td style="background-color: gray; color: whitesmoke;">
<asp:Label ID="csqnameLabel" runat="server" Text='<%# Eval("csqname") %>' />
</td>
<td>
<asp:Label ID="callswaitingLabel" runat="server" Text='<%# Eval("callswaiting") %>' />
</td>
<td>
<asp:Label ID="convoldestcontactLabel" runat="server" Text='<%# Eval("convoldestcontact") %>' />
</td>
<td>
<asp:Label ID="loggedinagentsLabel" runat="server" Text='<%# Eval("loggedinagents") %>' />
</td>
<td>
<asp:Label ID="availableagentsLabel" runat="server" Text='<%# Eval("availableagents") %>' />
</td>
<td>
<asp:Label ID="talkingagentsLabel" runat="server" Text='<%# Eval("talkingagents") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<ItemTemplate>
<tr id="MainTableRow" style="background-color: #DCDCDC; color: #000000;">
<td style="background-color: gray; color: whitesmoke;">
<asp:Label ID="csqnameLabel" runat="server" Text='<%# Eval("csqname") %>' />
</td>
<td>
<asp:Label ID="callswaitingLabel" runat="server" Text='<%# Eval("callswaiting") %>' />
</td>
<td>
<asp:Label ID="convoldestcontactLabel" runat="server" Text='<%# Eval("convoldestcontact") %>' />
</td>
<td>
<asp:Label ID="loggedinagentsLabel" runat="server" Text='<%# Eval("loggedinagents") %>' />
</td>
<td>
<asp:Label ID="availableagentsLabel" runat="server" Text='<%# Eval("availableagents") %>' />
</td>
<td>
<asp:Label ID="talkingagentsLabel" runat="server" Text='<%# Eval("talkingagents") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" data-height='100%'>
<tr runat="server" style="background-color: #113C77; color: #000000;">
<th runat="server"></th>
<th runat="server">Calls waiting</th>
<th runat="server">Current Wait</th>
<th runat="server">Agents Logged in</th>
<th runat="server">Ready</th>
<th runat="server">Talking</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
My C# code is:
public partial class csq_agent : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ListView1.DataSourceID = con_csq_agentDB.UniqueID;
}
}
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
ListViewDataItem dataitem = (ListViewDataItem)e.Item;
int callswaiting = (int)DataBinder.Eval(dataitem.DataItem, "callswaiting");
if (callswaiting == 3)
{
HtmlTableRow cell = (HtmlTableRow)e.Item.FindControl("MainTableRow");
cell.BgColor = "Red";
}
}
}

unable to export html table content to excel in asp.net

when the html table is exported to excel from asp.net the table is displayed but the content inside the table is not displayed below is my code.
protected void btnExportToExcel_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
lblCategorystatusReportHeader.Visible = true;
Response.AddHeader("content-disposition",
"attachment;filename=StatusReport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
//Panel preOrderPanel = (Panel)rpt1.FindControl("pnlPreOrder");
//rptCP.RenderControl(hw);
//pnlPreOrder.RenderControl(hw);
order.RenderControl(hw);
string output = sw.ToString();
output = "<html><head><meta charset=" + Encoding.UTF8.WebName + " /></head><body>" + output + "</body></html>";
Response.Output.Write(output);
Response.Flush();
Response.End();
lblCategorystatusReportHeader.Visible = false;
}
below is the aspx code
&nbsp
</asp:TableRow>
</asp:Table>
<table>
<tr>
<td>
&nbsp
</td>
</tr>
</table>
<table>
<%-- <tr style="text-align:center">
<td colspan="20" style="font-size:16px; padding-left:100px;background-color:#90cad9;border:1px solid black;display:none">
<b><asp:Label ID="lblCategorystatusReportHeader" runat="server" Text="Category Status Report"></asp:Label></b>
</td>
</tr>--%>
<tr>
<td style="width:150px !important;vertical-align:middle;text-align:center; border-style:solid; border-width:1px" rowspan="2">
<asp:Label ID="lblCPPre" runat="server"></asp:Label>
</td>
<td>
<%-- <asp:Panel ID="pnlPreOrder" runat="server">--%>
<table border="1" style="border-collapse:collapse">
<tr>
<%--<td stylwe="width:40px">
<asp:Label ID="lblCPPre" runat="server"></asp:Label>
</td>--%>
<td style="vertical-align:middle;background-color:#90cad9;text-align:center">
<div style="width:100px !important">Category CP</div>
</td>
<td>
<asp:Label ID="lblMessagePre" runat="server" Text="No Records found" Visible ="false" ForeColor="Red"></asp:Label>
<asp:Repeater ID="rptStylePO" runat="server" OnItemDataBound="rptStylePO_ItemDataBound">
<ItemTemplate>
<table border="1" style="border-collapse:collapse;border-spacing:0px">
<tr>
<td class="stylestatusReport">
<div style="width:100px !important"> <asp:HiddenField ID="styleid" runat="server" Value='<%# Container.DataItem.ToString() %>'/>
<asp:Label ID="lblStyle" runat="server"></asp:Label></div>
</td>
<td>
<asp:Label ID="lblNoMilestonePre" runat="server" Text="No Records found" Visible ="false" ForeColor="Red"></asp:Label>
<asp:Repeater ID="rptt" runat="server" OnItemDataBound="rptt_ItemDataBound">
<ItemTemplate>
<table>
<tr>
<td style="width:60px;vertical-align:middle;text-align:center">
<div style="width:60px !important"><asp:HiddenField ID="stlId" runat="server" Value='<%# Container.DataItem.ToString() %>' /></div>
</td>
<td>
<asp:DataList ID="dataListPO" runat="server" RepeatDirection="Horizontal" OnItemDataBound="dataListPO_ItemDataBound">
<ItemTemplate>
<table border="1" style="border-collapse:collapse; border-spacing:0px" >
<tr>
<td style="word-wrap:break-word;width:110px; height:60px; color:#000000;vertical-align:middle;text-align:center; background-color:#90cad9 ; font-size:11px;">
<div style="word-wrap:break-word;width:100%;font-size:13px">
<asp:Label ID="lblMilestoneValue" runat="server" Text='<%# Eval("MilestoneName") %>'></asp:Label></div>
</td>
</tr>
<tr>
<td style="text-align:left;">
<asp:Table ID="tblStatus" runat="server" Width="100%">
<asp:TableRow ID="rowStatus" runat="server">
<asp:TableCell ID="cellStatus1" Width="25px" runat="server"><div style="width:100px; text-align:justify"><asp:Label ID="lblForecastedDate" Font-Size="13px" runat="server" Width="50%" ForeColor="Black"></asp:Label></div></asp:TableCell>
<asp:TableCell ID="cellStatus" Width="25px" runat="server"> <div style="width:100px; text-align:center">
<asp:Label ID="lblStatus" Font-Size="13px" runat="server" ForeColor="White"></asp:Label></div>
</asp:TableCell>
</asp:TableRow></asp:Table>
<asp:HiddenField ID="hdnPlannedDate" runat="server" Value='<%# Eval("MilestonePlannedDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnRevisedDate" runat="server" Value='<%# Eval("MilestoneRevisedDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnActualDate" runat="server" Value='<%# Eval("MilestoneActualDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnMilestoneStatus" runat="server" Value='<%# Eval("MilestoneStatus") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
<%-- </asp:Panel>--%>
</td>
</tr>
<tr>
<td>
<%-- <asp:Panel ID="pnlPostOrder" runat="server">--%>
<table border="1" style="border-collapse:collapse;">
<tr>
<%--<td style="width:40px">
<asp:Label ID="lblCPPost" runat="server"></asp:Label>
</td>--%>
<td style=" background-color:#90cad9; font-size:14px;vertical-align:middle;text-align:center;white-space:nowrap; " ><div style="width: 100px;">Item CP</div></td>
<td style="font-size:14px">
<asp:Label ID="lblMessagePost" runat="server" Text="No Records found" Visible ="false" ForeColor="Red"></asp:Label>
<asp:Repeater ID="rptStylePostOrder" runat="server" OnItemDataBound="rptStylePostOrder_ItemDataBound">
<ItemTemplate>
<table border="1" style="border-collapse:collapse">
<tr>
<td class="stylestatusReport">
<div style="width:100px !important"><asp:HiddenField ID="styleid" runat="server" Value='<%# Container.DataItem.ToString() %>'/>
<asp:Label ID="lblStyle" runat="server"></asp:Label></div>
</td>
<td>
<asp:Label ID="lblNoMilestonePost" runat="server" Text="No Records found" Visible ="false" ForeColor="Red"></asp:Label>
<asp:Repeater ID="rptPO" runat="server" OnItemDataBound="rptPO_ItemDataBound">
<ItemTemplate>
<table>
<tr>
<td style="word-wrap:break-word;width:60px;vertical-align:middle;text-align:center;">
<div style="width:60px">
<asp:Label ID="lblPostOrderNumber" runat="server"></asp:Label>
<asp:HiddenField ID="hdnStylePOID" runat="server" Value='<%# Container.DataItem.ToString() %>'/></div>
</td>
<td>
<asp:DataList ID="dataListPostOrder" runat="server" RepeatDirection="Horizontal" OnItemDataBound="dataListPostOrder_ItemDataBound">
<ItemTemplate>
<table border="1" style="border-collapse:collapse">
<tr>
<td style="word-wrap:break-word;width:110px; height:60px;background-color:#90cad9 ; font-size:11px;vertical-align:middle;text-align:center">
<div style="word-wrap:break-word;width:100%; font-size:13px"><asp:Label ID="lblMilestoneValuePost" runat="server" Text='<%# Eval("MilestoneName") %>'></asp:Label></div>
</td>
</tr>
<tr>
<td style="text-align:left">
<asp:Table ID="tblStatusPost" runat="server" Width="100%">
<asp:TableRow ID="rowStatusPost" runat="server">
<asp:TableCell ID="cellStatus1Post" Width="25px" runat="server">
<div style="width:100px;text-align:justify;"><asp:Label ID="lblForecastedDatePost" Font-Size="13px" runat="server" Width="50%" ForeColor="Black"></asp:Label></div></asp:TableCell>
<asp:TableCell ID="cellStatusPost" runat="server"><div style="width:100px;text-align:center">
<asp:Label ID="lblStatusPost" Font-Size="13px" runat="server" Width="100%" ForeColor="White"></asp:Label></div></asp:TableCell></asp:TableRow></asp:Table>
<asp:HiddenField ID="hdnPlannedDatePost" runat="server" Value='<%# Eval("MilestonePlannedDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnRevisedDatePost" runat="server" Value='<%# Eval("MilestoneRevisedDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnActualDatePost" runat="server" Value='<%# Eval("MilestoneActualDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnMilestoneStatusPost" runat="server" Value='<%# Eval("MilestoneStatus") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
<%-- </asp:Panel>--%>
</td>
</tr>
</table>
[Below is the image of the table that is being displayed in excel.]
http://i.stack.imgur.com/JhHQo.png
actual image
[1]: http://i.stack.imgur.com/ghl8I.png

FindControl returns empty textbox object / null

I have a html table on a page:
<table id="tblMain" runat="server" style="margin-left: auto; margin-right: auto;">
<tr>
<td>
Safety
</td>
<td>
<asp:TextBox ID="txtSafety" Width="400px" ReadOnly="true" TextMode="MultiLine" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnSafety" runat="server" Width="150px" Text="Edit"
OnClick="Edit_Text" CommandArgument="0" />
</td>
</tr>
<tr>
<td>
Environment
</td>
<td>
<asp:TextBox ID="txtEnvironment" Width="400px" ReadOnly="true" TextMode="MultiLine" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="bntEnvironment" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="1" />
</td>
</tr>
<tr>
<td>
Quality
</td>
<td>
<asp:TextBox ID="txtQuality" Width="400px" ReadOnly="true" TextMode="MultiLine" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnQuality" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="2" />
</td>
</tr>
<tr>
<td>
Ferrous System
</td>
<td>
<asp:TextBox ID="txtFerrousSystem" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnFerrousSystem" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="3" />
</td>
</tr>
<tr>
<td>
Coke System
</td>
<td>
<asp:TextBox ID="txtCokeSystem" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnCokeSystem" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="4" />
</td>
</tr>
<tr>
<td>
Coal Yards
</td>
<td>
<asp:TextBox ID="txtCoalYards" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnCoalYards" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="5" />
</td>
</tr>
<tr>
<td>
Screenhouse
</td>
<td>
<asp:TextBox ID="txtScreenhouse" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnScreenhouse" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="6" />
</td>
</tr>
<tr>
<td>
Process Plant
</td>
<td>
<asp:TextBox ID="txtProcessPlant" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnProcessPlant" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="7" />
</td>
</tr>
<tr>
<td>
New Mill
</td>
<td>
<asp:TextBox ID="txtNewMill" Width="400px" ReadOnly="true" TextMode="MultiLine" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnNewMill" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="8" />
</td>
</tr>
<tr>
<td>
Streamphases
</td>
<td>
<asp:TextBox ID="txtStreamphases" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnStreamphases" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="9" />
</td>
</tr>
<tr>
<td>
Furnace Silos Injection
</td>
<td>
<asp:TextBox ID="txtFurnaceSilosInjection" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnFurnaceSilosInjection" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="10" />
</td>
</tr>
<tr>
<td>
CompressedAir
</td>
<td>
<asp:TextBox ID="txtCompressedAir" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnCompressedAir" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="11" />
</td>
</tr>
<tr>
<td>
Planned Maintenance
</td>
<td>
<asp:TextBox ID="txtPlannedMaintenance" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnPlannedMaintenance" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="12" />
</td>
</tr>
<tr>
<td>
Notifications Raised
</td>
<td>
<asp:TextBox ID="txtNotificationsRaised" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnNotificationsRaised" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="13" />
</td>
</tr>
<tr>
<td>
Manning
</td>
<td>
<asp:TextBox ID="txtManning" Width="400px" ReadOnly="true" TextMode="MultiLine" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnManning" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="14" />
</td>
</tr>
<tr>
<td>
ShiftHandover
</td>
<td>
<asp:TextBox ID="txtShiftHandover" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server" OnClick="Edit_Text"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnShiftHandover" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="15" />
</td>
</tr>
</table>
When the button is pressed the following method is called:
protected void Edit_Text(object sender, EventArgs e)
{
Button btn = sender as Button;
if (btn != null)
{
editField = btn.ID.Replace("btn", "");
btn.Visible = false;
//Getting and storing rowindex
TextBox txt = this.FindControl("txt" + editField) as TextBox;
txt.ReadOnly = false;
txt.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFFFB2");
txt.Focus();
comment = txt.Text;
//Further methods unnecessary for this question
}
}
As you can see, the prefix is stripped from the controls and then added in when necessary to find the right control at the point, therefore the string for the FindControl method is correct and should return a a TextBox.
However, by stepping through I can see that it is passing an empty TextBox instance rather than the expected result or a null.
I have already tried the findcontrol function on the table itself, I used 'this' as a second check but both yielded the same results.
I suspect the html table is a problem as in another method I am having issues finding a button manually in the html table:
Button editbtn = tblMain.Rows[GetRowIndex(hdnRowIndex.Value)].Cells[2].Controls[0] as Button;
Which is returning a null despite there always being a cell button in that cell for each row
EDIT - Here is the binding that is performed
private void bindData(DataTable dt)
{
if (dt.Rows.Count > 0)
{
foreach (DataColumn col in dt.Columns)
{
TextBox txt = tblMain.FindControl("txt" + col.ColumnName) as TextBox;
if (txt != null)
{
txt.Text = dt.Rows[0][col].ToString();
}
}
}
}
Your problem is here:
this.FindControl("txt" + editField) as TextBox;
FindControl is not recursive and can only find immediate children of the control it was called on. Here you are calling it of the page instance, so it only seeks through immediate children of the page in the control tree (presumably this is only a form element).
What you need to do is to pick a server-side control right above your textboxes/buttons and run FindControl of it. For instance, let's say it is your table, which is declared as:
<table>
<%--...all the content from the post goes here...--%>
</table>
Make this table server-side:
<table id="TheTable" runat="server">
and then call FindControl on this table:
TextBox txt = TheTable.FindControl("txt" + editField) as TextBox;
You can of course keep the table client-side, and use some control that wraps this table. Just make sure that in between your control and the textbox in question there are no other server-side controls.
<table style="width:100%; margin-left:auto; margin-right:auto;" id="tblTst" runat="server">
<tr>
<td>
<h2>
Vehicle Information
<asp:Label ID="lblTest" Text="THis is a Test" ForeColor="Salmon" runat="server" />
<asp:Button ID="btnTest" CommandArgument="0" OnClick="btnTest_click" runat="server" Text="Test" />
</h2>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblTst2" Text="This is also a Test" ForeColor="Salmon" runat="server" />
<asp:Button ID="btnTest2" CommandArgument="1" OnClick="btnTest_click" runat="server" Text="Test" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblMsg" runat="server" />
</td>
</tr>
</table>
protected void btnTest_click(object sender, EventArgs e)
{
Button btn = sender as Button;
string comment = "";
string editField = "";
if (btn != null)
{
editField = btn.ID.Replace("btn", "");
btn.Visible = false;
//Getting and storing rowindex
foreach(HtmlTableCell cl in tblTst.Rows[Convert.ToInt32(btn.CommandArgument)].Cells)
{
foreach (Control ctrl in cl.Controls)
{
if(ctrl is Label)
{
Label txt = new Label();
txt = ctrl as Label;
txt.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFFFB2");
txt.Focus();
comment = txt.Text;
lblMsg.Text = comment;
return;
}
}
}
//Further methods unnecessary for this question
}
}
}
This is what I came up with, this does work; however it is a fairly dirty way to do this, I'm sure you can clean it up quite a bit. This is only intended as a starting point. The big different is that you need to look in the cell for the control not in the table or page, also the cell is an htmltable cell not just a table cell.

SqlDataSource UpdateCommand parameters not changing

I have a FormView with an UpdateButton and a SqlDataSource which are below. My updatebutton always update the Sil table with the same values (the values at the first line of my gridview), I couldn't figure out why.
<asp:FormView ID="frm_Benefit" runat="server" DataKeyNames="ID" DataSourceID="sds_Benefits"
OnItemInserted="frm_Benefit_ItemInserted" OnItemUpdated="frm_Benefit_ItemUpdated">
<EditItemTemplate>
<table class="formview">
<tr>
<td>
Code:
</td>
<td>
<asp:TextBox ID="CodeTextBox" runat="server" Text='<%# Bind("Code") %>' />
</td>
</tr>
<tr>
<td>
Name:
</td>
<td>
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
</td>
</tr>
<tr>
<td>
HRName:
</td>
<td>
<asp:TextBox ID="HRNameTextBox" runat="server" Text='<%# Bind("HRName") %>' />
</td>
</tr>
<tr>
<td>
Description:
</td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'
TextMode="MultiLine" MaxLength="200" />
</td>
</tr>
<tr>
<td>
Associated Url:
</td>
<td>
<asp:TextBox ID="UrlTextBox" runat="server" Text='<%# Bind("Url") %>' MaxLength="100" />
</td>
</tr>
<tr>
<td>
BenefitType:
</td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="sds_BenefitTypes"
DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("BenefitTypeID") %>'>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Cost:
</td>
<td>
<asp:TextBox ID="CostTextBox" runat="server" Text='<%# Bind("Cost") %>' />
</td>
</tr>
<tr>
<td>
Cost Type:
</td>
<td>
<asp:DropDownList ID="CostTypeDropDown" runat="server" DataSourceID="sds_CostTypes"
DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("CostTypeID") %>'>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Quantity Type:
</td>
<td>
<asp:DropDownList ID="QuantityTypeDropDown" runat="server" DataSourceID="sds_QuantityTypes"
DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("QuantityTypeID") %>'>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Quantity Entry On Add:
</td>
<td>
<asp:CheckBox ID="QuantityEntryOnAddCheckBox" runat="server" Checked='<%# Bind("QuantityEntryOnAdd") %>' />
</td>
</tr>
<tr>
<td>
Quantity Entry On Remove:
</td>
<td>
<asp:CheckBox ID="QuantityEntryOnRemoveCheckBox" runat="server" Checked='<%# Bind("QuantityEntryOnRemove") %>' />
</td>
</tr>
<tr>
<td>
Bonus Ratio:
</td>
<td>
<asp:TextBox ID="BonusRatioTextBox" runat="server" Text='<%# Bind("BonusRatio") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
ApplyIncomeTax:
</td>
<td>
<asp:CheckBox ID="ApplyIncomeTaxCheckBox" runat="server" Checked='<%# Bind("ApplyIncomeTax") %>' />
</td>
</tr>
<tr>
<td>
ApplyStampTax:
</td>
<td>
<asp:CheckBox ID="ApplyStampTaxCheckBox" runat="server" Checked='<%# Bind("ApplyStampTax") %>' />
</td>
</tr>
<tr>
<td class="style1">
ApplySocialSecurityTax:
</td>
<td class="style1">
<asp:CheckBox ID="ApplySocialSecurityTaxCheckBox" runat="server" Checked='<%# Bind("ApplySocialSecurityTax") %>' />
</td>
</tr>
<tr>
<td>
Applicable Location:
</td>
<td>
<asp:DropDownList ID="CostTypeDropDown1" runat="server" DataSourceID="sds_Locations"
DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("ApplicableLocationID") %>'>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2">
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Update" Style="display: none" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" Style="display: none" />
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="sds_Benefits" runat="server" ConnectionString="<%$ ConnectionStrings:ConnFlexibleBenefitsDB %>"
SelectCommand="SELECT * FROM [View_Benefits]"
UpdateCommand="UPDATE [Sil] SET [Code] = #Code, [HRName] = #HRName WHERE [Id] = #Id">
<UpdateParameters>
<asp:Parameter Name="Code" Type="String" />
<asp:Parameter Name="HRName" Type="String" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
And this is my gridview:
<asp:GridView ID="grd_Benefits" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
CssClass="gridTable" DataSourceID="sds_Benefits" OnRowCommand="grd_Benefits_RowCommand">
<RowStyle CssClass="gridRow" />
<FooterStyle CssClass="gridFooter" />
<SelectedRowStyle CssClass="gridSelectedRow" />
<HeaderStyle CssClass="gridHeader" />
<AlternatingRowStyle CssClass="gridAlternatingRow" />
<EmptyDataTemplate>
No records found.
</EmptyDataTemplate>
<Columns>
<asp:BoundField DataField="Code" HeaderText="Code" SortExpression="Code" />
<asp:BoundField DataField="HRName" HeaderText="HRName" SortExpression="HRName" />
<asp:TemplateField HeaderText="Benefit Type" SortExpression="BenefitType.Name">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("BenefitTypeName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Cost" HeaderText="Cost" SortExpression="Cost" />
<asp:TemplateField HeaderText="Cost Type">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("CostTypeName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity Type">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("QuantityTypeName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbSelect" runat="server" CausesValidation="False" CommandName="ViewRecord"
Text="<img border='0' alt='Edit' src='../images/zoom.gif' />" CommandArgument='<%# Container.DataItemIndex %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<HeaderTemplate>
<asp:LinkButton ID="lbInsert" runat="server" CausesValidation="false" CommandName="NewRecord"
Text="<img border='0' alt='New' src='../images/new.gif' />" CommandArgument='<%# Container.DataItemIndex %>'
ForeColor="White"></asp:LinkButton>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="False" CommandName="EditRecord"
Text="<img border='0' alt='Edit' src='../images/edit.gif' />" CommandArgument='<%# Container.DataItemIndex %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
RowCommand:
protected void grd_Benefits_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ViewRecord")
{
grd_Benefits.SelectedIndex = int.Parse(e.CommandArgument.ToString());
frm_Benefit.ChangeMode(FormViewMode.ReadOnly);
Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFormViewView", "<script type=\"text/javascript\">showFormViewView();</script>");
}
else if (e.CommandName == "NewRecord")
{
frm_Benefit.ChangeMode(FormViewMode.Insert);
Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFormViewInsert", "<script type=\"text/javascript\">showFormViewInsert();</script>");
}
else if (e.CommandName == "EditRecord")
{
grd_Benefits.SelectedIndex = int.Parse(e.CommandArgument.ToString());
frm_Benefit.ChangeMode(FormViewMode.Edit);
Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFormViewEdit", "<script type=\"text/javascript\">showFormViewEdit();</script>");
}
}
Seeing your Markups and taking it as it is, the issue is with the FormView.
You have not set the AllowPaging="true" for FormView. So every time the FormView displays, it will just Display only the First Row of all the data records retrieved.
[ Note that Form View displays only one single record at a time ].
So every time you are selecting 'Edit' in Form View, you are actually editing the First record only ( which is indeed the First row of GridView).
Set the AllowPaging property to true for FormView.
<asp:FormView ID="frm_Benefit" runat="server" DataKeyNames="CustomerID"
DataSourceID="sds_Benefits" OnItemUpdated="frm_Benefit_ItemUpdated"
AllowPaging="true">
After that using the Paging index, navigate to any record you want to change and edit it as seen below.

Categories