locked
Gridview column data not showing same as it in textbox RRS feed

  • Question

  • User-807418713 posted

    Hello

    I have one textbox in which i have enter data like this below and click save to database table

    On gridview it shows like this below

    but i want same what i have entered in textbox

    how to do so..

    thanking you

    Wednesday, June 24, 2020 7:03 AM

All replies

  • User288213138 posted

    Hi Gopi.MCA,

    i want same what i have entered in textbox

    According to your description, I couldn’t understand your requirement clearly.

    Shouldn't the content in the textbox be entered by yourself?

    Can you post your code and more details information about your requirement.

    Best regards,

    Sam

    Wednesday, June 24, 2020 8:18 AM
  • User-807418713 posted

    Hello

    Shouldn't the content in the textbox be entered by yourself? YES

    The SAME I Want To show in gridview column..

    Wednesday, June 24, 2020 8:54 AM
  • User288213138 posted

    Hi Gopi.MCA,

    The SAME I Want To show in gridview column.

    Do you want to make the style in Gridview the same as TextBox?

    Best regards,

    Sam

    Wednesday, June 24, 2020 9:08 AM
  • User-807418713 posted

    Hello

    I have textbox in that i enter data then i click save button it save to database table

    then i use select query to bind that field to gridview column

    i want to show same design what i entered in textbox

    hope this clear

    Wednesday, June 24, 2020 9:28 AM
  • User475983607 posted

    Try placing the content inside of <pre></pre> tags which keeps the plain text formatting.  Otherwise, it is up to you to design a style and write code to meet the style requirements. The community cannot accurately answer this question as we do not have you styles. 

    Wednesday, June 24, 2020 12:54 PM
  • User288213138 posted

    Hi Gopi.MCA,

    I have textbox in that i enter data then i click save button it save to database table

    then i use select query to bind that field to gridview column

    i want to show same design what i entered in textbox

    GridView is a table, but the style of your GridView above is not the style of the table.

    I wrote a demo for you as a reference, does it meet your requirement?

    <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" ></asp:TextBox>
                <asp:Button ID="Button1" runat="server" Text="Save" OnClick="Button1_Click" />
                <asp:GridView ID="GridView1" runat="server"></asp:GridView>
    
    
    protected void Button1_Click(object sender, EventArgs e)
            {
                string text = TextBox1.Text;
                string[] words = text.Split(new[] { System.Environment.NewLine }, StringSplitOptions.None);
    
                string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
                foreach (var word in words)
                {
                    string query = "INSERT INTO Test5 VALUES(@value)";
                    using (SqlConnection con = new SqlConnection(constr))
                    {
                        using (SqlCommand cmd = new SqlCommand(query))
                        {
                            cmd.Parameters.AddWithValue("@value", word);
                            cmd.Connection = con;
                            con.Open();
                            cmd.ExecuteNonQuery();
                            con.Close();
                        }
                    }
                }
                Bind();
            }
            public void Bind()
            {
                string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
                string query = "SELECT * FROM Test5";
                using (SqlConnection con = new SqlConnection(constr))
                {
                    using (SqlDataAdapter sda = new SqlDataAdapter(query, con))
                    {
                        using (DataTable dt = new DataTable())
                        {
                            sda.Fill(dt);
                            GridView1.DataSource = dt;
                            GridView1.DataBind();
                        }
                    }
                }
            }

    The result:

    Best regards,

    Sam

    Thursday, June 25, 2020 3:09 AM
  • User-2054057000 posted

    This can be achieved by css styling. You have to add style="text-align: left" to your text box.

    Thursday, June 25, 2020 5:05 AM
  • User-807418713 posted

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1031: Type expected

    Source Error:

    Line 254:
    Line 255:                 string text = TextBox1.Text;
    Line 256:                 string[] lines = text.Split(new[] { System.Environment.NewLine }, StringSplitOptions.None);

    Sunday, June 28, 2020 2:28 PM
  • User288213138 posted

    Hi Gopi.MCA,

    Compilation Error

    CS1031: Type expected

    string[] lines = text.Split(new[] { System.Environment.NewLine }, StringSplitOptions.None);

    It works fine on my side. 

    What is the version of your .net framework? My version is 4.7.2.

    Best regards,

    Sam

    Tuesday, June 30, 2020 2:01 AM