I have 4-5 checkbox
inside gridview. I want to save its value into the database like,
If checked == true
, then "Y"
else "N"
I tried like below
foreach (GridRow row in GrdRights.Rows)
{
xw.WriteElementString("ADD_FLAG", chkadd.Checked == true ? "Y" : "N");
xw.WriteElementString("MODIFY_FLAG", chkedit.Checked == true ? "Y" : "N");
xw.WriteElementString("VIEW_FLAG", chkview.Checked == true ? "Y" : "N");
xw.WriteElementString("DEL_FLAG", chkdelete.Checked == true ? "Y" : "N");
}
but got error as
object reference not set to an instance of an object
I defined all checkboxes as below
GridDataControlFieldCell chkcellAdd = GrdRights.RowsInViewState[i].Cells[4] as GridDataControlFieldCell;
GridDataControlFieldCell chkcellView = GrdRights.RowsInViewState[i].Cells[5] as GridDataControlFieldCell;
GridDataControlFieldCell chkcellEdit= GrdRights.RowsInViewState[i].Cells[6] as GridDataControlFieldCell;
GridDataControlFieldCell chkcellDelete = GrdRights.RowsInViewState[i].Cells[7] as GridDataControlFieldCell;
CheckBox chkadd = chkcellAdd.FindControl("ChkIDAdd") as CheckBox;
CheckBox chkview = chkcellView.FindControl("ChkIDView") as CheckBox;
CheckBox chkedit = chkcellEdit.FindControl("ChkIDEdit") as CheckBox;
CheckBox chkdelete = chkcellDelete.FindControl("ChkIDDelete") as CheckBox;
I tried a link from here but getting the same error.
Please suggest what is wrong here
HTML of my gridview:-
<cc2:Grid ID="GrdRights" runat="server" FolderStyle="../Styles/Grid/style_12"
AllowSorting="False" AutoGenerateColumns="False" AllowColumnResizing="true" AllowAddingRecords="false"
AllowMultiRecordSelection="true" OnRowDataBound="GrdRights_RowDataBound" ViewStateMode="Enabled"
PageSize="100">
<ClientSideEvents OnClientSelect="FunMonthList" />
<ScrollingSettings ScrollHeight="400px" />
<Columns>
<cc2:Column ID="Column1" DataField="MKEY" ShowHeader="false" HeaderText="Select" ReadOnly="true"
Width="5%" runat="server">
<TemplateSettings TemplateId="TemplateWithCheckbox" />
</cc2:Column>
<cc2:Column ID="Column2" DataField="parent_menu" HeaderText="MENU" Visible="true"
ReadOnly="true" Width="10%" runat="server">
</cc2:Column>
<cc2:Column ID="Column4" DataField="child_menu_mkey" Visible="false" ReadOnly="true"
Width="10%" runat="server">
</cc2:Column>
<cc2:Column ID="Column3" DataField="child_menu" HeaderText="SUB MENU" runat="server"
Visible="true" Width="30%">
</cc2:Column>
<%--<cc2:Column ID="Column5" DataField="MKEY" ShowHeader="false" HeaderText="Select" ReadOnly="true" Width="5%" runat="server">
<TemplateSettings TemplateId="TemplateWithCheckbox" />
</cc2:Column>--%>
<cc2:CheckBoxColumn Id="chkAdd" DataField="ADD_FLAG" ShowHeader="true" HeaderText="Add"
Width="5%" runat="server" Align="right">
<TemplateSettings TemplateId="TemplateWithChecAdd" />
</cc2:CheckBoxColumn>
<cc2:CheckBoxColumn Id="chkEdit" DataField="MODIFY_FLAG" ShowHeader="true" HeaderText="Edit"
Width="5%" runat="server" Align="right">
<TemplateSettings TemplateId="TemplateWithChecEdit" />
</cc2:CheckBoxColumn>
<cc2:CheckBoxColumn Id="ChkView" DataField="VIEW_FLAG" ShowHeader="true" HeaderText="View"
Width="6%" runat="server" Align="right">
<TemplateSettings TemplateId="TemplateWithChecView" />
</cc2:CheckBoxColumn>
<cc2:CheckBoxColumn Id="ChkDelete" DataField="DEL_FLAG" ShowHeader="true" HeaderText="Delete"
Width="8%" runat="server" Align="right">
<TemplateSettings TemplateId="TemplateWithChecDelete" />
</cc2:CheckBoxColumn>
</Columns>
<Templates>
<cc2:GridTemplate ID="TemplateWithChecAdd">
<Template>
<asp:CheckBox runat="server" ID="ChkIDAdd" ToolTip="<%# Container.Value %>" />
</Template>
</cc2:GridTemplate>
<cc2:GridTemplate ID="TemplateWithChecView">
<Template>
<asp:CheckBox runat="server" ID="ChkIDView" ToolTip="<%# Container.Value %>" />
</Template>
</cc2:GridTemplate>
<cc2:GridTemplate ID="TemplateWithChecEdit">
<Template>
<asp:CheckBox runat="server" ID="ChkIDEdit" ToolTip="<%# Container.Value %>" />
</Template>
</cc2:GridTemplate>
<cc2:GridTemplate ID="TemplateWithChecDelete">
<Template>
<asp:CheckBox runat="server" ID="ChkIDDelete" ToolTip="<%# Container.Value %>" />
</Template>
</cc2:GridTemplate>
</Templates>
</cc2:Grid>
Aucun commentaire:
Enregistrer un commentaire