Tuesday, December 14, 2010

Datalist Customization by using Radiobuttons and Hyperlink by emailid requirement

here i need to design the following manner

Radiobutton To CC EmpRole-EmpFirsname EmpLastname(empemail@emp.com)
check the following image

Test.aspx:
==========
 <asp:DataList runat="server" ID="emailaddress" Width="433px">
                            <ItemTemplate>
                                <asp:CheckBox ID="ToEmailCheck" runat="server" GroupName="rdbEmailAddress" AutoPostBack="true" OnCheckedChanged="EmailCheck_CheckedChanged"
                                    EnableViewState="False" />
                                <asp:Label ID="lblRoleCode" runat="server"
                                    Text='<%# Eval("cpx_cpo_code","-")%>' />
                                <asp:Label ID="lblFirstname" runat="server" Text='<%#Eval("ind_first_name") %>' />
                                <asp:Label ID="lblLastname" runat="server" Text='<%#Eval("ind_last_name") %>' />
                                <asp:HyperLink ID="TomailAddress" runat="server" Font-Underline="True" NavigateUrl='<%# Eval("cst_eml_address_dn", "mailto:{0}") %>'
                                    Text='<%# Eval("cst_eml_address_dn", "({0})") %>' />
                            </ItemTemplate>
                        </asp:DataList>

here my requirement is i need to add the email address of the employees to the TOTextbox but it not fall in the CCTextbox


Test.aspx.cs:
=============
protected void EmailCheck_CheckedChanged(object sender, EventArgs e)
        {
            //txtCC.Text = string.Empty;
            //txtTo.Text = string.Empty;
            for (int i = 0; i < this.emailaddress.Items.Count; i++)
            {
                if (((CheckBox)emailaddress.Items[i].FindControl("CCEmailCheck")).Checked == true &&
                    ((CheckBox)emailaddress.Items[i].FindControl("ToEmailCheck")).Checked == false)
                {
                    // add to list
                    if (txtCC.Text.Length > 0)
                    {
                        string remove = txtTo.Text.Replace(((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString(), "");
                        txtTo.Text = remove;
                        txtCC.Text += "," + ((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString().TrimStart('(');
                        txtCC.Text = txtCC.Text.TrimEnd(')');
                        txtCC.Text = txtCC.Text.ToString();
                    }
                    else
                    {
                        string remove = txtTo.Text.Replace(((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString(), "");
                        txtTo.Text = remove;
                        txtCC.Text += ((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString();
                        txtCC.Text = txtCC.Text.TrimStart('(');
                        txtCC.Text = txtCC.Text.TrimEnd(')');
                        txtCC.Text = txtCC.Text.ToString();
                    }
                }
                else if (((CheckBox)emailaddress.Items[i].FindControl("ToEmailCheck")).Checked == true &&
                    ((CheckBox)emailaddress.Items[i].FindControl("CCEmailCheck")).Checked == false)
                {
                    if (txtTo.Text.Length > 0)
                    {
                        string remove = txtCC.Text.Replace(((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString(), "");
                        txtCC.Text = remove;
                        txtTo.Text += "," + ((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString().TrimStart('(');
                        txtTo.Text = txtTo.Text.TrimEnd(')');
                        txtTo.Text = txtTo.Text.ToString();
                    }
                    else
                    {
                        string remove = txtCC.Text.Replace(((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString(), "");
                        txtCC.Text = remove;
                        txtTo.Text += ((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString();
                        txtTo.Text = txtTo.Text.TrimStart('(');
                        txtTo.Text = txtTo.Text.TrimEnd(')');
                        txtTo.Text = txtTo.Text.ToString();
                    }
                }
            }

        }

No comments:

Post a Comment