DataGrid: Bound Column vs Template Column

I have a datagrid with a bound column and a template column as given below.

When I scan through the grid, I get the value of the first column (bound column). However, I cannot get the value of the second column (Template Column). I can see the data in both columns though.

////////////////////////////////////////////////////////////////////////////////////
<AlternatingItemStyle BackColor="#e0e0e0"></AlternatingItemStyle>
<Columns>
<asp:BoundColumn DataField="Facility" HeaderText="Facility"> </asp:BoundColumn>
<asp:TemplateColumn HeaderText="Facility2">
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
</ItemTemplate>
</asp:TemplateColumn>
////////////////////////////////////////////////////////////////////////////////////

foreach (System.Web.UI.WebControls.DataGridItem GridRow in Grid.Items)
{
string str_first_column_value = GridRow.Cells[0].Text ///returns good value
string str_second_column_value = GridRow.Cells[1].Text //returns no value
}

Is there any other syntax to retrieve the TemplateColumn value?
0
nair7
4/4/2006 2:28:18 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
815 Views

Similar Articles

[PageSpeed] 9

since it's an itemtemplate accessing is a lil different---you could do something like this

variable = CType (dgManagerView.Items(x).Cells(9).Controls(1), Label).Text

Not sure on the sequence for C# but it should be somewhat similar


My Regards to All,
Jason -- O-H-I-O Go Buckeyes! #1
--- LIVESTRONG.ORG --- Please support the battle against cancer!
0
onewisehobbit
4/4/2006 3:00:18 PM

Try this. 

.aspx

<asp:TemplateField HeaderText="Description" SortExpression="Description">
    <ItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server" Text="Test" />
    </ItemTemplate>
</asp:TemplateField>
 .aspx.cs 
foreach (System.Web.UI.WebControls.DataGridItem GridRow in Grid.Items)
{
    TextBox tb = (TextBox)GridRow.FindControl("TextBox1");
    string str_first_column_value = GridRow.Cells[0].Text; 
    string str_second_column_value = tb.Text; 
}
 
0
sophia
4/14/2006 9:27:26 AM
Reply:

Similar Artilces:

in a grid how to find a particular column is bound column or template column
hi,  Any one know how to find a particular column is bound column or template column or button column,etc in a grid Advance thanks   hi...use this dim label1 as Label=ctype(GridView1.FindControl("name"),Label) Hope This HelpsBhaaratRemember to click "Mark as Answer" on the post that helps UMy Blog find a particular column is bound column or template column no to find that particular column  Hi,please excuse me if iam wrong.i found that bount columns values are directly renders to a <td>  where template columns create some cont...

Setting Datagrid Column to invisible when Column is an AutoGeneratedColumn NOT a bound Column
Hi all, Just like the title says, I'm trying to set a column to invisible but I'm unable to do so. If I bound the column I can used the code: me.datagrid.Column.Item(1).Visible = False But since I'm wanting the column NOT to be bound (there are a number of sql scripts that populate the same datagrid so I cannot bound all the columns since the columns are different for each script etc etc etc) how do I set an AutoGeneratedColumn to invisible?? Please help! Andrewwww.codingmayhem.com - VB.NET, C#, Silverlight, Javascript, HTML, CSS, T-SQL, MySQL and SQLitewww.headshot...

Issue with Template Columns & Bound Columns while updating the data in a GridView control
Hi, I'm facing the below problem (In general, ObjectDataSource is driving me crazy ! ) I have a simple gridview control and an ObjectDataSource is used to populate the grid. I'm trying to update a row and the corresponding tableadapter methods & stored procedure are in place. Each row has 2 checkboxes and 2 textboxes in edit mode. When the change the values in edit mode and hit update, the checkbox values changed are saved into the Database properly, whereas the textbox values are not being saved. If the textbox column is a bound column then the column is updated with <NULL> in...

Dynamic change the 'Read Only' in datagrid(template column/Bound column)
I create few template column and bound column in datagrid. One of the template column contain the StudentMark. I want to know how to change that column to (Read only) or "Not" (Read only) when click the edit button. It is based on a dropdownlist to determine to read only or not. I think i must use the template column, since i need to do the validation to the StudentMark. (For example, If select value '1' in dropdownlist, the "StudentMark" is become 'Read only' and select '2' become vice versa. I was success to bind the datagrid and "StudentMark" become a textbox...

Datagrid Bound Column needs to be bound to 2 columns?a valu
Hi I have a datagrid with dynamically bounded columns. One column has to display a value that will come from 2 columns in the database. Is there a way to do this? the code I have for the moment is: 'Add columns 'Code Dim col1 As New BoundColumn col1.HeaderText = cLang.read("code") col1.DataField = "Patient_Code" 'this needs to be 2 database columns!! dtaSearchresult.Columns.Add(col1) .. .. .. .. Thx alot! Combine the two columns in your SELECT statement eg SELECT <PatientCol1>+<PatientCol2> AS Patient_Code FR...

Bound columns and template columns in Gridview
Hello Everyone, In my gridview, I changed some of the bound columns to template columns, I noticed that the template column is not recognized inside the RowDataBound event method. The reason I changed the bound columns to template columns so that I can add the total column in the footer. I guess I cannot do that with bound columns. If I do e.Row.Cells[5].Text then  5th column is not recognixed inside the Rowdatabound event, but If i do e.Row.Cells[4].Text then  it is recognized. Please let me know what am I doing wrong. <asp:GridView ID="dgAgentActivity" runat="server" AutoGen...

converting Bound Column to Template Column
Hi All, I wanted to convert the bound column in the grid to Template column. How could I do this dynamically? I know it can be done using the edit column dialog box, but I need to do that in the code behind. waiting for your reply. Thanks, regards,   Hi Techwork, Not tested and incomplete but just to get you going: Iterate the Columns property and find the BoundField with:Columns[i].GetType().Name == "BoundField" and((BoundField)Columns[i]).DataField == ... Remove this BoundField from the Columns Collection with:Columns.RemoveAt(i); Create a new TemplateField insta...

How to order columns in datagrid with template columns
I have a datagrid with two template columns that appear in positions 0  and 1  on my datagrid.  How can I move these template columns to other postions?   -smc~ Remember To Mark The Posts Which Helped You As The ANSWER ~  Change to source view, look for the <asp: ..... </asp:....> within the <Columns> .... </Columns> and, cut and paste into the required position. <Columns>  <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True"  SortExpression="Id" >    <I...

Text in bound column vs button column
Why does this code NOT work if the column is a button column? It seems not to be reading what text is in the column, but does if it is bound. Private Sub dgTest_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgTest.ItemCommand If e.CommandName = "Bio" Then Dim idCell As TableCell = e.Item.Cells(4) Session("testSess") = idCell.Text End If End Sub I have tried a few things different but with no luck. Always seem to be creating another hi...

datagrid columns bound to columns from different tables
Hi, I have a dataset with multiple tables. Is there a way to bind each of the datagrid's columns to a column from a different tables? Thanks in advance! BR The bottom line, yes you can, but it would take some custom methods getting called from a template column and some other fancy tricks. But, the datagrid is designed and works best when it's given it's one datasource. If you need data from different columns in different tables, I would make a custom datatable that reflects the columns you need and use that custom datatable has the datagrid's datasource. Don't think of t...

Datagrid Control, template columns
Hi all i am working on datagrid control. I have to columns both are template columns.The first template column contains a textbox control, the second column contains a dropdownlist. I need to bind the data to the first column fileupload control and the dropdownlist should be populated from the database. How do i go about doing this please help me.  Hi...If u want to Bind Text Box From Data Base then Bind TextBox Template as like below                          &l...

Problem: Template Column Converts To ( Bound ?) Column On PostBack
I have a template column in a datagrid and I have a button that allows the user to copy data from the second column into the template column, though when the user hits this button the template column converts to a bound column (or what appears to be a bound column). Any ideas how to resolve, thanks. Is there a different function for updating a template column ?For copying data form a bound column into a template column I am using this function:foreach(DataGridItem dgi in DataGrid1.Items){dgi.Cells[3].Text = dgi.Cells[4].Text;}...

Datagrid Problems persist.....Button Column..Template Column
Which is best for my needs..I have a datagrid that displays huge amounts of data......I use a Push button with the text details as a column.....Obvisouly I need some way of tracking each button pushed to 'pop' up a specific page with details on that person of which their detail button on their row was clicked...I have been looking on the net but can't quite figure this out........Is there a simple way of doing so......Code examples....Please help If i got you question correct, you need to attach an id of the person to the button click. You will have to use a templateColumn, place a button ...

Inherited controls in datagrid template columns
Hi all,I have created inherited HyperLink control as follows Public Class ResourceHyperLink        Inherits HyperLink        Private m_ResourceID As Integer        Private m_ResouceName As String        Public Property ResourceName() As String            Get                ResourceName = m_ResouceName    &...

Web resources about - DataGrid: Bound Column vs Template Column - asp.net.presentation-controls

Resources last updated: 11/21/2015 4:49:02 PM