Tuesday, 7 February 2017

  Select One Checkbox

 <script type="text/javascript">
        function CheckBoxCheck(rb) {
            var gv = document.getElementById("<%=datagrid.ClientID%>");
            var chk = gv.getElementsByTagName("input");
            var row = rb.parentNode.parentNode;
            for (var i = 0; i < chk.length; i++) {
                if (chk[i].type == "checkbox") {
                    if (chk[i].checked && chk[i] != rb) {
                        chk[i].checked = false;
                        break;
                    }
                }
            }
        }
    </script>

 <asp:TemplateField HeaderStyle-Width="20px" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:CheckBox runat="server" ID="chkRow"  OnCheckedChanged="chkRow_CheckedChanged" AutoPostBack="true"  onclick="CheckBoxCheck(this)" />
                            </ItemTemplate>
                         </asp:TemplateField>

foreach (GridViewRow row in datagrid.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chkRow = (row.Cells[1].FindControl("chkRow") as CheckBox);
                    if (chkRow.Checked == true)
                    {
                        lblprofileid.Text = row.Cells[2].Text;
                        int Id = Convert.ToInt32(row.Cells[2].Text);
                        var View = (from P in pe.TblProfiles where P.ProfileId == Id select P).ToList();
                        imgPhoto.ImageUrl = View.ToList()[0].Image;

                        string[] Profile_Name = row.Cells[3].Text.Split(' ');
                        txtFirstName.Text = Profile_Name[0];
                        txtMiddleName.Text = Profile_Name[1];
                        txtLastName.Text = Profile_Name[2];
                        ddlCountry.SelectedValue = row.Cells[4].Text.ToString();
                        ddlState.SelectedValue = row.Cells[5].Text.ToString();
                        ddlCity.SelectedValue = row.Cells[6].Text.ToString();
                        txtAddress.Text = row.Cells[7].Text;
                        txtEmail.Text = row.Cells[8].Text;

                        string[] MobNo = row.Cells[9].Text.Split('-');
                        txtMobCode.Text = MobNo[0];
                        txtMobNo.Text = MobNo[1];

                        //if (MobNo = row.Cells[9].Text.ToString())
                        //{
                        //    txtMobCode.Text = MobNo[0];
                        //    txtMobNo.Text = MobNo[1];
                        //}
                        //else
                        //{
                        //    txtMobNo.Text = row.Cells[9].Text;
                        //}

                        btnSubmit.Text = "Update";
                    }
                }
            }

No comments:

Post a Comment