473,388 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Pass textbox value to a column in gridview

6
In my gridview, I have 6 columns. In the 6th column I want to display a value from textbox from same form. The value should be displayed on the row next to last row of rest of the columns. So my last column (i.e.) 6th column will just have 1 row irrespective of number of rows in rest of the columns.

How do I achieve this? Please help me. I have been trying a lott but couldnt figure out.
Jul 15 '10 #1
4 5305
djpaul
137 100+
Hey,
Try this:
Expand|Select|Wrap|Line Numbers
  1. DataGridView1.Item("ColumnName", 0).Value = TextBox1.Text
Greetz,
Paul
Jul 15 '10 #2
SK2010
6
Thanks Paul for helping me solve my problem.

I tried doing as you said, but I got an error message "System.Web.UI.WebControls.GridView does not contain a definition for Item"

I have put this line of code in my databound event. Am I doing anything wrong?

Here is my databound event code:
Expand|Select|Wrap|Line Numbers
  1. GridView gvr = sender as GridView;
  2.  
  3.         if (gvr != null)
  4.        {
  5.                GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
  6.  
  7.                 TableCell cell = new TableCell();
  8.                 cell.ColumnSpan = 1;
  9.                 cell.HorizontalAlign = HorizontalAlign.Center;
  10.                 cell.Text = "Quantity";
  11.                 row.Cells.Add(cell);
  12.  
  13.                 cell = new TableCell();
  14.                 cell.ColumnSpan = 4;
  15.                 cell.HorizontalAlign = HorizontalAlign.Center;
  16.                 cell.Text = "Description";                 
  17.                 row.Cells.Add(cell);
  18.                 //grdItems.Rows[2].Cells[3].Text = "sample Text"; 
  19.  
  20.  
  21.                 cell = new TableCell();
  22.                 cell.ColumnSpan = 1;
  23.                 cell.HorizontalAlign = HorizontalAlign.Center;
  24.                 cell.Text = "Total Amount";
  25.                 row.Cells.Add(cell);
  26.  
  27.                 grdItems.Controls[0].Controls.AddAt(0, row);
  28.                 grdItems.Item("Total Amount", 0).Value = txtAmtDue.Text;
  29.  
  30.             }
  31.  
Jul 16 '10 #3
djpaul
137 100+
Oh sh...t. Sorry, it was on asp.net. I don't know much about that.
Maybe you could try:

Expand|Select|Wrap|Line Numbers
  1. grdItems.Rows[1].Cells[3].Text = txtAmtDue.Text;
Hope that will help you...
Cheers!
Jul 16 '10 #4
SK2010
6
djpaul,

Thanks for helping me. I tried as you said...but it didnt work...

I tried using template field and then bind the value but for some reason I dont see the value when I run the page.

here is my sql query I used to bind the gridview:
Select bi.*, b.cAmtDue AS cAmtDue FROM bod_items bi, bod_inv b WHERE bi.cInvNum = '" + Request.QueryString["cInvNum"].ToString() + "' and bi.cInvNum = b.cInvNum

Here is my aspx for grid:
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="grdItems"  runat="server" AllowSorting="True" AutoGenerateColumns="False"
  2.             BackColor="White" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"
  3.             CellPadding="4" ForeColor="Black" GridLines="Vertical" width="670px" Font-Size="Smaller">
  4.             <Columns>
  5.             <asp:TemplateField HeaderText="ROWID" SortExpression="rowid" Visible="False">
  6.                     <EditItemTemplate>
  7.                         <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("rowid") %>'></asp:TextBox>
  8.                     </EditItemTemplate>
  9.                     <ItemTemplate>
  10.                         <asp:Label ID="lblRowID" runat="server" Text='<%# Bind("rowid") %>'></asp:Label>
  11.                     </ItemTemplate>
  12.                     <HeaderStyle Font-Size="Small" HorizontalAlign="Center" />
  13.                     <ItemStyle Font-Names="Arial" Font-Size="Smaller" />
  14.                 </asp:TemplateField>
  15.                ...
  16.  
  17.  
  18.       <asp:TemplateField>   
  19.  
  20.       <HeaderTemplate>Total Amount</HeaderTemplate>   
  21.       <FooterTemplate>   
  22.       <table border="1" cellpadding="0" cellspacing="0" width="100%">   
  23.       <ItemTemplate>
  24.          <asp:Label ID="lblRowID" runat="server" Text='<%# Eval("cAmtDue") %>'></asp:Label>
  25.       </ItemTemplate>
  26.       <ItemTemplate>
  27.           <asp:Label ID="Label7" runat="server" Text='<%# Eval("cAmtDue") %>'></asp:Label>
  28.       </ItemTemplate>      
  29.       </table>   
  30.       </FooterTemplate>   
  31.       </asp:TemplateField>   
  32.      </Columns>
  33.  ...
  34.         </asp:GridView>
  35.  
Jul 19 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: SDRoy | last post by:
Hi Can someone help me to figure out how to get the editable textbox value from GridView in my code-behind ? I am using the code something like- GridView2.Rows.Cells.Text.Trim(). But when I...
1
by: swatidesai0407 | last post by:
im working on php i want the textbox value to pass in a href it goes as this <input type="text" name="use"> <a href="new.php?cat=textbox value dat is entered"> plz tell me wat to do
3
by: jed | last post by:
I need to pass a value that is inserted by the user in a textbox to a variable in my stored procedure. please help
0
by: discussion | last post by:
Hello, I am doing a small project in VB6 using MSAccess as database can someone guide me how to --- I have a form which ask user to enter value for two text boxes FROMDATE and TODATE . and form...
1
by: tina2626 | last post by:
how can i pass textbox value to gridview using C#.net at runtime not using database values. i m hving textbox1 and gridview1. can anyone suggest me to do this coding in ASP.NET(C# language).
8
by: tina2626 | last post by:
how can i pass textbox value to gridview using C#.net at runtime not using database values. i m hving textbox1 and gridview1. can anyone suggest me to do this coding in ASP.NET(C# language).
0
by: dan | last post by:
Hi, I have a multi-line textbox in a gridview when in edit mode. The textbox (rendered as textarea in browser) set cols to 20 by default. I'd like the textbox to 'adjust' itself to the width...
1
by: adepvivek | last post by:
Hi everybody, I am using textbox in gridview as template. And I want to stored the value of textbox. For that I want to pass the textbox value to stored procedure. So please give me solution.
0
by: baburmm | last post by:
Hai, I want to get the footer textbox value in gridview using javascript any one help me Regards, Babu.K
8
by: hiranmaie | last post by:
Hi, I am having 3 textboxes and 1 gridview. I want to pass (reflect) the values from textboxes to gridview. I am not using the database here. I want to save the data directly from textboxes...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.