I have a scenario as below.
There are 3 check boxes.3 textbox associated with each.Grid gets populated on entering a search value in the textbox.On selecting a row on this grid,I need to hide the grid and selected value(one column) is populated into another textbox.I am getting "Object reference not set to an instance of an object.",when I implementing the logic for hiding the grid.Checkbox checked,value entered in search textbox,grid is populated ,a row selected,second textbox populated with grid value,grid gets hidden--> after this process repeated for 2-3 times,again checking on a check box gives the error.
Please find the markup with above controls.
On selecting a row on the grid,I am populating name column value to a textbox and hiding the grid as below.
Above mentioned checkboxes act like radio buttons and javascript for the same is as below
Grid gets populated on textchanged event and 'onkeyup="KeyUp();' function of the textbox,associated with it as below.
aspx:
code behind:
On checkedchanged eveent of check boxes,I am making the grid visible.
Ajaxmanager is as below:
I hope hiding/unhiding the grid gives me the error.Please suggest your ideas on this.
Thanks,
Soumya
There are 3 check boxes.3 textbox associated with each.Grid gets populated on entering a search value in the textbox.On selecting a row on this grid,I need to hide the grid and selected value(one column) is populated into another textbox.I am getting "Object reference not set to an instance of an object.",when I implementing the logic for hiding the grid.Checkbox checked,value entered in search textbox,grid is populated ,a row selected,second textbox populated with grid value,grid gets hidden--> after this process repeated for 2-3 times,again checking on a check box gives the error.
Please find the markup with above controls.
<table width="500px"> <tr> <td> <fieldset id="fssearch" runat="server"> <legend>Search </legend> <table> <tr> <td> <asp:CheckBox ID="CBFile" runat="server" Text="File No" OnCheckedChanged="CBFile_CheckedChanged" AutoPostBack="true" /> </td> <td> <asp:CheckBox ID="CBname" runat="server" Text="Patient Name" OnCheckedChanged="CBname_CheckedChanged" AutoPostBack="true" /> </td> <td> <asp:CheckBox ID="CBMobile" runat="server" Text="Mobile No" OnCheckedChanged="CBMobile_CheckedChanged" AutoPostBack="true" /> </td> </tr> <tr> <td> <asp:TextBox ID="RTFileS" onkeyup="KeyUp();" runat="server" OnTextChanged="RTFileS_TextChanged" Visible="false"></asp:TextBox> </td> <td colspan="2"> <asp:TextBox ID="RTNameS" onkeyup="KeyUp();" runat="server" OnTextChanged="RTNameS_TextChanged" Visible="false"></asp:TextBox> </td> <td> <asp:TextBox ID="RTMobileS" onkeyup="KeyUp();" runat="server" OnTextChanged="RTMobileS_TextChanged" Visible="false"></asp:TextBox> </td> </tr> <tr> <td colspan="4"> <telerik:RadGrid ID="gvPatientList" runat="server" AllowFilteringByColumn="True" AllowPaging="True" GridLines="None" OnSelectedIndexChanged="gvPatientList_SelectedIndexChanged" > <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" /> <GroupingSettings CaseSensitive="false" /> <ItemStyle HorizontalAlign="Left" /> <HeaderStyle HorizontalAlign="Left" /> <AlternatingItemStyle HorizontalAlign="Left" /> <ClientSettings EnablePostBackOnRowClick="true"> <Selecting AllowRowSelect="true" /> </ClientSettings> <MasterTableView AutoGenerateColumns="False" DataKeyNames="pt_regid"> <CommandItemTemplate> <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> </CommandItemTemplate> <Columns> <telerik:GridBoundColumn HeaderText="Patient Name" UniqueName="pt_name" DataField="pt_name" AllowFiltering="false"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="File No" UniqueName="pt_fileno" DataField="pt_fileno" AllowFiltering="false"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Mobile" UniqueName="pt_pmobileno" DataField="pt_pmobileno" AllowFiltering="false"> </telerik:GridBoundColumn> </Columns> </MasterTableView> <HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Default"> </HeaderContextMenu> </telerik:RadGrid> </td> </tr> </table> </fieldset> </td> </tr> </table>On selecting a row on the grid,I am populating name column value to a textbox and hiding the grid as below.
protected void gvPatientList_SelectedIndexChanged(object sender, EventArgs e) { GridDataItem RegId = gvPatientList.SelectedItems[0] as GridDataItem; string regid = RegId.GetDataKeyValue("pt_regid").ToString(); foreach (GridDataItem dataItem in gvPatientList.Items) { if (dataItem.Selected) { RCFName.Text = dataItem["pt_name"].Text; } } gvPatientList.Visible = false; }Above mentioned checkboxes act like radio buttons and javascript for the same is as below
<script language="CS" runat="server"> private void makeRadioGroupFromCheckBoxes(IEnumerable<CheckBox> checkBoxes) { StringBuilder sb = new StringBuilder(); foreach (CheckBox cb in checkBoxes) { foreach (CheckBox innercb in checkBoxes) { if (innercb != cb) { sb.Append("document.getElementById('"); sb.Append(innercb.ClientID); sb.Append("').checked = false;"); } } cb.Attributes["onclick"] = "if(this.checked){" + sb.ToString() + "}else{this.checked = true;}"; sb = new StringBuilder(); } } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { this.makeRadioGroupFromCheckBoxes(new CheckBox[] { CBFile, CBname, CBMobile }); } }aspx:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> <script type="text/javascript"> var timer = null; function KeyUp() { if (timer != null) { clearTimeout(timer); } timer = setTimeout(LoadTable, 500); } function LoadTable() { $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("FilterGrid"); } </script> </telerik:RadCodeBlock>protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e) { if (e.Argument.IndexOf("FilterGrid") != -1) { gvPatientList.Rebind(); } } protected void RTFileS_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(RTFileS.Text)) { _scheduleService = new ScheduleService(); clsSchedule clsschedule = new clsSchedule(); string search = " where OldRegnNo like '" + RTFileS.Text + "%" + "'"; gvPatientList.DataSource = _scheduleService.GetAllPatients(search); //gvPatientList.MasterTableView.Rebind(); gvPatientList.Rebind(); } }protected void CBFile_CheckedChanged(object sender, EventArgs e) { if (CBFile.Checked) { RTFileS.Visible = true; gvPatientList.Visible = true; gvPatientList.MasterTableView.Visible = true; gvPatientList.Rebind(); } else { RTFileS.Visible = false; } }Ajaxmanager is as below:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="gvPatientList"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="gvPatientList" LoadingPanelID="RadAjaxLoadingPanel1" /> <telerik:AjaxUpdatedControl ControlID="RCFName" /> <%--<telerik:AjaxUpdatedControl ControlID="CBFile" /> <telerik:AjaxUpdatedControl ControlID="CBname" /> <telerik:AjaxUpdatedControl ControlID="CBMobile" />--%> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="gvPatientList" LoadingPanelID="RadAjaxLoadingPanel1" /> </UpdatedControls> </telerik:AjaxSetting>I hope hiding/unhiding the grid gives me the error.Please suggest your ideas on this.
Thanks,
Soumya