You must Sign In to post a response.
  • Category: ASP.NET

    Display multiple colors with multiple textboxes

    hi friends,
    how to display the multiple colors in multiple textboxs using database.for example i'am selecting colors in color pikker at a time the color will be stored in database as well as bind in multiple textboxes with different colors in asp.net.
    Thank you,
  • #763046
    Hello Sadiq,

    In your previous thread i have replied the all possible ways with source code and explanation also.
    Link of previous thread :
    http://www.dotnetspider.com/forum/343269-using-color-pickers-in-aspnet.aspx

    than why you posted that thread's discussion in new thread. You should continue with thread. I was continuously responding to your thread.

    By doing this you are creating spam on DNS.

    Hope you understand.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763047
    Hi sadiq,

    I guess already you post the same post previously and Nirav give the solution for the same, then what's your problem again?

    If you did it for one textbox for one color, then you can incorporate it for multiple textboxes with different colors what's the wrong in that, try to implement first, if you struck in any place then we will help you..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #763048
    thank u for responding.
    please check the my code
    protected void Button1_Click(object sender, EventArgs e)
    {
    SqlConnection con = new SqlConnection("Data Source=sadiq-pc;Initial Catalog=sadiqsql;User ID=sa;Password=sadiq");
    con.Open();
    string s = "insert into color values('" + TextBox1.Text + "')";
    SqlCommand cmd = new SqlCommand(s,con);
    int i=cmd.ExecuteNonQuery();

    if (i == 1)
    {

    string s1 = "select name from color";
    SqlCommand cmd1 = new SqlCommand(s1, con);
    //SqlDataReader dr = da.ExecuteReader();
    //if (dr.HasRows)
    //{
    // dr.Read();
    // TextBox2.BackColor = System.Drawing.ColorTranslator.FromHtml(dr[0].ToString());
    // dr.Dispose();
    //}
    SqlDataAdapter da = new SqlDataAdapter(cmd1);
    DataTable dt = new DataTable();
    da.Fill(dt);
    if (dt.Rows.Count > 0)
    {

    TextBox2.BackColor = System.Drawing.ColorTranslator.FromHtml(dt.Rows[0].ToString());
    TextBox3.BackColor = System.Drawing.ColorTranslator.FromHtml(dt.Rows[1].ToString());
    TextBox4.BackColor = System.Drawing.ColorTranslator.FromHtml(dt.Rows[2].ToString());
    TextBox5.BackColor = System.Drawing.ColorTranslator.FromHtml(dt.Rows[3].ToString());
    }
    }


    con.Close();

    Delete Attachment

  • #763049
    see the screen shot in this i have four text boxes and in this if i select the any color in color picker show the color in txtbox1 and next i'am selecting another color this color show another txt box and next again upto last text box.
    i hope you u understanding this.
    thank you

  • #763050
    Hi sadiq,

    As per my understand the code your requirement is you are selecting the color code from picker and when you click "save" it should be saved in database table and that saved value you want be show it in textbox, if the database contains 4 rows then 4 textboxes should filled up the appropriate color right?

    First debug the code and check what is datatable result, and how many rows it contains and whether the value is showed in textbox or not? Please check it and let me know..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #763051
    Hello Sadiq,

    Refer the below code :

    HTML Mark-up :

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>

    </head>
    <body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
    <asp:TextBox ID="TextBox1" runat="server" ReadOnly="true" AutoPostBack="false"></asp:TextBox>
    <asp:HiddenField ID="HiddenField1" runat="server" />
    <script type = "text/javascript">
    function Color_Changed(sender) {
    sender.get_element().value = "#" + sender.get_selectedColor();
    var txtval = document.getElementById('<%= TextBox1.ClientID %>').value;
    document.getElementById('HiddenField1').value = txtval;
    }
    </script>
    <cc1:ColorPickerExtender ID="ColorPickerExtender1" runat="server" TargetControlID="TextBox1" SampleControlID="TextBox1" PopupButtonID="TextBox1" PopupPosition="Right" OnClientColorSelectionChanged="Color_Changed"/>
    <asp:Button ID="ButtonSave" runat="server" Text="Save" OnClick="ButtonSave_Click"/><br/><br/>
    <asp:TextBox ID="TextBox2" runat="server" ReadOnly="true"></asp:TextBox><br/><br/>
    <asp:TextBox ID="TextBox3" runat="server" ReadOnly="true"></asp:TextBox><br/><br/>
    <asp:TextBox ID="TextBox4" runat="server" ReadOnly="true"></asp:TextBox><br/><br/>
    <asp:TextBox ID="TextBox5" runat="server" ReadOnly="true"></asp:TextBox>
    </div>
    </form>
    </body>
    </html>

    Code-behind :

    using System.Data;
    using System.Data.SqlClient;

    SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|Database1.mdf;Integrated Security=True");
    SqlCommand cmd;
    SqlDataAdapter sda;

    protected void ButtonSave_Click(object sender, EventArgs e)
    {
    try
    {
    con.Open();
    cmd = new SqlCommand("INSERT INTO Color(ColorName) VALUES('" + HiddenField1.Value + "')", con);
    int i = cmd.ExecuteNonQuery();
    con.Close();

    if (i == 1)
    {
    DataTable dt = new DataTable();
    con.Open();
    sda = new SqlDataAdapter("SELECT ColorName FROM Color", con);
    sda.Fill(dt);

    if (dt.Rows.Count > 0)
    {
    TextBox2.BackColor = System.Drawing.ColorTranslator.FromHtml(dt.Rows[0][0].ToString());
    TextBox3.BackColor = System.Drawing.ColorTranslator.FromHtml(dt.Rows[1][0].ToString());
    TextBox4.BackColor = System.Drawing.ColorTranslator.FromHtml(dt.Rows[2][0].ToString());
    TextBox5.BackColor = System.Drawing.ColorTranslator.FromHtml(dt.Rows[3][0].ToString());
    }
    }
    }
    catch (Exception ex)
    {
    Response.Write("<script>alert('" + Server.HtmlEncode(ex.Message) + "')</script>");
    }
    finally
    {
    con.Close();
    }
    }

    See the attached image. It's an output i have got using above code,

    I think this what you are looking for.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #763054
    Thank you
    exactly this one. but when i run this it's searching for all values at a time.that's why it's show the error.because when i insert one value show the color in txtbox1 and next again inserting the value show the color in text box2 and also same.i want like this.

  • #763056
    Hello Sadiq,

    You can't expect like this thing from us.

    I have provided you the source code also not the way only. Now you try by your self and grow up your self man.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763060
    Hi

    You have already posted the same question and you got responses as per your requirement in below thread.
    http://www.dotnetspider.com/forum/343269-using-color-pickers-in-aspnet.aspx
    Why you are creating duplicate posts.
    Editors should remove these duplications.

    Regards

    Sai Krishna Reddy.


Sign In to post your comments