In the gridview (enableviewstate = false), the first column is a boundfield having a DataField = "CallDetailID" and the second column is a checkbox (enableviewstate = false), and there are other columns.
The code-behind for a button on the page goes through all the checkboxes that are selected and retrieves the CallDetailID. When the CallDetailID boundfield visibility is true then I can retrieve the IDs, but when the visibility is set to false the IDs cannot be retrieved.
Is there a setting on the gridview that has to be changed?
Here is some of the aspx and c# code:
gvCallDetails.Rows.Cells[0].Text doesn't retrieve the CallDetailID for the selected checkboxes unless the visibility of the CallDetailID boundfield is true.
The code-behind for a button on the page goes through all the checkboxes that are selected and retrieves the CallDetailID. When the CallDetailID boundfield visibility is true then I can retrieve the IDs, but when the visibility is set to false the IDs cannot be retrieved.
Is there a setting on the gridview that has to be changed?
Here is some of the aspx and c# code:
Code:
<asp:GridView runat="server" ID="gvCallDetails" AutoGenerateColumns="false" OnSorting="gvCallDetails_Sorting"
OnRowCommand="gvCallDetails_RowCommand" OnRowDataBound="gvCallDetails_DataBound" BorderStyle="Solid"
CssClass="dealgrid" BackColor="white" CellPadding="0" CellSpacing="0" GridLines="None" BorderColor="#4D80D1"
BorderWidth="1px" AllowSorting="true" AllowPaging="false" PageSize="10" EnableViewState="False" DataKeyNames="CallDetailID">
<RowStyle CssClass="gridbody" />
<AlternatingRowStyle CssClass="altgridbody" />
<HeaderStyle HorizontalAlign="Center" CssClass="GridviewFixedHeader" ForeColor="White" />
<Columns>
<asp:BoundField DataField="CallDetailID" Visible="false" ReadOnly="true" />
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox CssClass="cbody" ID="chkHeaderSelect" runat="server" AutoPostBack="true" EnableViewState="false" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox CssClass="cbody" ID="chkSelected" runat="server" EnableViewState="false" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"/>
<HeaderStyle Width="60px" />
</asp:TemplateField>
Code:
int iResult;
StringBuilder sbCallDetail = new StringBuilder();
//GridViewRow row = new GridViewRow();
for (int i = 0; i <= gvCallDetails.Rows.Count - 1; i++)
{
if ((((CheckBox)gvCallDetails.Rows[i].FindControl("chkSelected")).Checked) == true)
{
sbCallDetail.Append(gvCallDetails.Rows[i].Cells[0].Text + ',');
}
}