Forum guidelines
AuthorQuestion
GRidview Textboxes
Posted on: 01 Dec 2012
hi,

i am using 4 text boxes and a grid view in one of my application.I need to add the textbox values to the gridview,clear the textbox values and then enter the values into textboxes and click on button they should again go to gridview and the previously saved in the gridview should also be their in the gridview


Every Time i Enter values the 3rd and the 4th textbox values should add to the previous entered values and should be displayed on the gridivew


Please Helpme out

Santosh Pisipati
AuthorReply
dev soni
  • 1
  • 0
accepted
Re: GRidview Textboxes
Posted on: 04 Dec 2012   Accepted Answer
hi santosh,
paste this code in WebForm1.aspx page
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Add to grid" 
            onclick="Button1_Click" />
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
now paste this code in code behind page 
 static DataTable dt = new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (dt.Columns.Count == 0)
            {
                dt.Columns.Add("text1");
                dt.Columns.Add("text2");
                dt.Columns.Add("text3");
                dt.Columns.Add("text4");
            } 
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            DataRow dr = dt.NewRow();
            dr["text1"] = TextBox1.Text;
            dr["text2"] = TextBox2.Text;
            dr["text3"] = TextBox3.Text;
            dr["text4"] = TextBox4.Text;
            dt.Rows.Add(dr);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }

now run the code and with this you will be able to add the dynamic values to the grid.i hope this works for you.
Regards
Devendra

Re: GRidview Textboxes
Posted on: 10 Dec 2012  
That worked perfectly,also i have one more query regarding masked textboxes..
i have got some masked textboxes and they start with $0.00 say they should be inserted into gridview with same decimals.
Again They should retrieve back with the same decimals into another textbox on button click.
Early Reply is Needed Please
Thank You,

Santosh Pisipati
Re: GRidview Textboxes
Posted on: 10 Dec 2012  
hey i don't think it is any kind of problem.it will work with this code.
Add any data into the textbox and click on the add button and the data would be inserted into the Grid. :)
and if you can provide me the code then it will be easy to reply with the working code.:)

Re: GRidview Textboxes
Posted on: 10 Dec 2012  
Values are not inserting with the mask in the gridview ..
Say if the textbox is masked in $0.00 fromat it should be saved in the save pattern in the gridview..but it is not ..



Santosh Pisipati
Re: GRidview Textboxes
Posted on: 10 Dec 2012  
ok i got
just replace the Button_click code with below given code it will work for you
  protected void Button1_Click(object sender, EventArgs e)
        {
            DataRow dr = dt.NewRow();
            dr["text1"] = TextBox1.Text.Trim()==""?$0.00: TextBox1.Text;
            dr["text2"] = TextBox2.Text.Trim()==""?$0.00: TextBox2.Text;
            dr["text3"] = TextBox3.Text.Trim()==""?$0.00: TextBox3.Text;
            dr["text4"] = TextBox4.Text.Trim()==""?$0.00: TextBox4.Text;
            dt.Rows.Add(dr);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }

i hope this code will work for you
Thanks
Dev :)


Re: GRidview Textboxes
Posted on: 10 Dec 2012  
throws a syntax error.. also sorry for not saying i Have used Radcontrol For the radTextboxes
Dev If You Wont Mind R u Familiar With Telerik Radcontrols ??

If Yes ther is another Doubt Regarding  rad Ribbon Bar and Rad Tab Strip..

dr["Billed Us For"] = radbilledusfor.Text.Trim()==""?$0.00: radbilledusfor.Text;

Santosh Pisipati
Re: GRidview Textboxes
Posted on: 10 Dec 2012  
replace the code with this one
$0.00 to "$0.00" it will work for you

thanks
Dev
 :)

Re: GRidview Textboxes
Posted on: 10 Dec 2012  
Nope, That is not working ..



Santosh Pisipati
Re: GRidview Textboxes
Posted on: 10 Dec 2012  
have you tried like this
        protected void Button1_Click(object sender, EventArgs e)
        {
            DataRow dr = dt.NewRow();
            dr["text1"] = TextBox1.Text.Trim()==""?"$0.00": TextBox1.Text;
            dr["text2"] = TextBox2.Text;
            dr["text3"] = TextBox3.Text;
            dr["text4"] = TextBox4.Text;
            dt.Rows.Add(dr);
            GridView1.DataSource = dt;
            GridView1.DataBind();

        }

if not than try above given code otherwise send me the button click code ,if you can :)
then i can look into the prob.

Thanks
Dev

Re: GRidview Textboxes
Posted on: 10 Dec 2012  

                DataRow dr = dt.NewRow();
                dr["freight Bill#"] = radfrieght.Text;
                dr["Balance $"] = radbal.Text;
                dr["Their Pro"] = radtheirpro.Text;
                dr["Billed Us For"] = radbilledusfor.Text.Trim()==""?"$0.00": radbilledusfor.Text;
                dr["Settled For"] = radsettledfor.Text.Trim() == "" ? "$0.00" : radsettledfor.Text;
                dt.Rows.Add(dr);
                GridView1.DataSource = dt;
                GridView1.DataBind();
                GridView1.DataBind();
                int sum = 0;
                for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
                {
                    sum += int.Parse(GridView1.Rows[i].Cells[3].Text);
                }
                radsofar.Text = sum.ToString();
                radleft.Text = "-" + radsofar.Text;
                int sum1 = 0;
                for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
                {
                    sum1 += int.Parse(GridView1.Rows[i].Cells[4].Text);
                }
                radgiveup.Text = sum1.ToString();
                radcount.Text = Convert.ToString(GridView1.Rows.Count);
                cleartextboxes();



Yes i have tried but isn't coming..

Santosh Pisipati
Re: GRidview Textboxes
Posted on: 10 Dec 2012  
hi santosh can you send me what error exactly you are getting.And
check the value of textboxes with debugging. Code is absolutely fine and working for me.so check with debugging.try this also
 TextBox1.Text==string.Empty|| TextBox1.Text.Trim()==""?"$0.00": TextBox1.Text;

Thanks
Dev

Re: GRidview Textboxes
Posted on: 10 Dec 2012  
I am not getting any error,also i am not getting it in the Mask Format,

Also I have attached the Screen shot

Santosh Pisipati
Re: GRidview Textboxes
Posted on: 10 Dec 2012  
one last thing
have you checked the value of textbox with debugging,if not then do debugging and lemme know the value or you can print the value of textbox with this
put this line in as first line of button click
if it is Webapplication then
Response.Write(radbilledusfor.Text.Trim());
if it is winodow then
MessageBox.Show(radbilledusfor.Text.Trim());
and lemme know that value



Re: GRidview Textboxes
Posted on: 10 Dec 2012  
Values in the Texboxes are same without the mask ie;
if i enter the Value as $1.11 it shows 111 in the Gridview i Have attached it in the Debugging Mode.


Santosh Pisipati
Re: GRidview Textboxes
Posted on: 10 Dec 2012  
i understand the issue
code is fine but the masking of the textbox is not right so change the ways of masking.
is it a window application or web application ?
i am damn sure about this
change the masking or find out the problem with the masking.


Thanks
Dev

Re: GRidview Textboxes
Posted on: 10 Dec 2012  
its an web application.

Also Dev are you familiiar with Telerik Radcontrols??

Santosh

Santosh Pisipati
Re: GRidview Textboxes
Posted on: 10 Dec 2012  
Also dev
i Hav got a textbox and itshoud be validated with a query.On tabchange to another textbox field itshoud be validated with a query and return it and not able to write in the next textbox untill the first textbox is validated



Santosh Pisipati

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.