.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

Gridview: can we use asp:TemplateField and asp:BoundField both in a single grid??

Posted By:      Posted Date: October 06, 2010    Points: 0   Category :ASP.Net

Hello everybody

can we use asp:TemplateField and asp:BoundField both in a single grid??

If yes then how to handle deleteCommand on serial number. mean to say how to write query for that field as it is not any column of databse..

for e.g--


            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
                <asp:TemplateField HeaderText="Serial No">

View Complete Post

More Related Resource Links

Building a grouping Grid with GridView and ASP.NET AJAX toolkit CollapsiblePanel

I've posted an update to this post to apply on demand loading of Details data using ASP.NET AJAX PageMethods. I'm demonstrating the usage if CollapsiblePanelExtender client events on the new post. Check it out.

I admit, Matt Berseth is really inspiring me! Few days ago I pass through 2 of his great posts:

.Surrounding your Data Table and Dialog Controls with ComponentArt Styled Panels
.Building a Grouping Grid with the ASP.NET 3.5 LinqDataSource and ListView Controls
The first one is pure design tips one which I used for making good presentation of my demo here. The 2nd post is actually the idea.

DataFormatString in a BoundField of a GridView

I had a simple little problem - the DataFormatString="{0:0}" in a BoundField was not working

GridView: Move Over DataGrid, There's a New Grid in Town!


When incorporating the ASP.NET DataGrid control into your Web apps, common operations such as paging, sorting, editing, and deleting data require more effort than you might like to expend. But all that is about to change. The GridView control--the successor to the DataGrid-- extends the DataGrid's functionality it in a number of ways. First, it fully supports data source components and can automatically handle data operations, such as paging, sorting, and editing, as long as its bound data source object supports these capabilities. In addition, the GridView control offers some functional improvements over the DataGrid. Here DataGrid expert Dino Esposito introduces the GridView and explains all its long-awaited features.

Dino Esposito

MSDN Magazine August 2004

Custom Grid View Header - Grid view Row Created event vs Gridview row databound events ?


Hi Gurus ,

It happened to add an extra Gridveiw Header in row_databound event , It did worked fine on !Postback but disappered on Page.Postback . Quick google search guided me to move the event to Row_Created event and every thing is okay .

Can any expert post some pointers , differnces between grid row_created vs row_databount with some sample table data created dynamically  behaviour of both the events in !Postback and page.Postback .

Thanks a tonne in Advance and  any inputs will be valued and appreciated .

Master-Detail GridView in Single Page example with paging throws error

___http://www.java2s.com/Code/ASP/Data-Binding/MasterDetailGridViewinSinglePage.htmI followed example at the link above.When I enablind paging=true (by pagesize=3).and clicking to pages 2|3|4 etc and so;error occuringIndex was out of range. Must be non-negative and less than the size of the collection.at cs line :sourceProducts.SelectParameters[0].DefaultValue = gridMaster.DataKeys[e.Row.DataItemIndex].Value.ToString();got any idea?what should I make to fix this ? is this error  fixable ?thanks much.

Templatefield CheckBox in gridview acting strange

I have an ASP.NET page that contains a gridview. I have to create columns dynamically based on a datatable, some field type info and some header texts. I do that by creating templates. It created the grid fine and all looks good, however when i click a checkbox and the checkedchanged event fires then something odd happens The first time i click its fine and i get the expected values in the event But the second time then the event gets fired with the values from the first time and then again with the values from the checkbox that i actually clicked.. The third time the event gets fired 3 times, first 2 times with the old values and the third with the correct value. And it just keeps going like that Furthermore Let us say i have 10 checkboxes that are checked when i uncheck one the checkedchanged event fires but if i check it again the event doesnt fire and also if i have unchecked 3 checkboxes(and get the extra events) then if i check one of them again i get 2 checked changed events fired for the ones that are still unchecked but no event gets fired for the box that i checked  so now im just baffled   See pastebin link below for code: http://pastebin.com/stcwqsYa 

asp:TemplateField Visible upon condition in grid view

Hi, Is there a way to show or hide a Template Field within a gridview upon a condition in C#? Thanks! 

Add TextBoxes and Grid in Single WebForm.

Hi All,   Actually i want to create Invoice Web Form Using C#, Asp.Net.But I have no idea about how to add grid view and text boxes in single form. As Text Boxes of Form will store in Invoice header Table and Item Which i have added in that should store in Item Table. (if you have any other suggestion for db structure please suggest me.)  This Form will have 8 Textboxes beside gridview and one gridview. TextBoxes are as below:- 1)Invoice Number(AutoNumber). 2)Invoice Date(will be filled Manually). 3)Customer Name(DropDown or AutoComplate TextBox). 4)Customer Address (Will  be filled as i select Customer). 5)Customer Representative(Will be Dropdown list or Auto Complete TextBox and will be filtered on Customer Name). 6)"Create" Button (It will fill the above TextBoxes Data In InvoiceHeader Table and Reserve Invoice Number and Catch ID of Invoice Number to use for Grid View.)   When I click Create Button System Will also Show me the Hidden GridView and Attached TextBoxes to Fill data in Grid. There will be  textboxes.   1) Item Code (Will be AutoComplete TextBox and Data Will be retrived from ItemTable and Only Pick Items Which are in Stock.) 2) Item Name (Will be autofilled when i select Item Code.) 3) Item Qty(Will be autofilled when i select Item Code.) 4) Item Stock Date (Will be autofilled when i select Item Co

GridView, TemplateField and ButtonField

I have a grid view in which i have  1.5 boundfields 2.A templatefield containing a dropdownlist having values accept and decline 3.A buttonfield with TextProperty as ok After selecting Accept in dropdownlist and clicking on the OK button, The row of a status column in one of my Database Table should be updated from No to Yes. If the user selects Decline in the dropdownlist and then clicks on the OK button, I want that row to be deleted. I also have a unique id as boundfield in the GridView. Please advise how to achieve this HI All,I have a grid view in which i have -a)5 BoundFieldsb)A TemplateField containing a dropdownlist having values accept and declinec)A ButtonField with TextProperty as OK.After selecting Accept in dropdownlist and clicking on the OK button, The row of a status column in one of my Database Table should be updated from No to Yes.If the user selects Decline in the dropdownlist and then clicks on the OK button, I want that row to be deleted.I also have a unique id as BoundField in the GridView.Please advise me how to achieve this

Dynamic templatefield disappear during gridview rowcommand

Hi,   I already implemented the dynamic templatefield which will re-created in every postback. Everytime I make a postback in the page I see no problem but when I click my imagebutton inside the gridview then the dynamic templatefield disappear. To double check if it is really gone at all I just select the second page of the gridview using my customize paging using dropdownlist outside the gridview and the templatefield with its correct data reappear again. I already put a variable inside the rowcommand to see if the number of columns are the same with the number of columns the gridview render together with the dynamic templatefield during debugging and it is there but cannot render that templatefield in the client.   Any ideas? 


the database result is as follows DATE     code   class1 class2  class3 1/8/10     M1     10       20     30     3/8/10     V2      20       30     10      1/8/10      H1      1           2      3         7/8/10     ! ! 8/8/10     !M2    5      5      5       3/8/10     B2      4      4     4       1/8/10     V1      3      7     3       THE OUTPUT SHOULD BE AS FOLLOWS:- DATE           M1                          M2           

no data in gridview templatefield

I have a gridview bound to a objectdatasource, when I try to convert one of my columns to a template field the data doesn't displayBefore converting <asp:BoundField DataField="ID" Visible="false" /> <asp:BoundField DataField="Contract" HeaderText="Contract" /> <asp:BoundField DataField="Tender" HeaderText="Tender" /> After converting <asp:BoundField DataField="ID" Visible="false" /> <asp:BoundField DataField="Contract" HeaderText="Contract" /> <asp:TemplateField HeaderText="Tender"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Tender") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("Tender") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> Im usig the option in the gridview smarttags Convert this field into a TemplateField . When run as a bound field the data appears, when run as as template the data doesn't, Is there something I'm missing?    

GridView - putting TemplateField fields in between data bound fields


Here is my problem.  I have a GridView, and I want Column1 to be equal to datatable data (filled by a SqlDataAdapter).  Then I have two other fields by the SqlDataAdapter (first name, last name), and I want to have those two fields combined to form Column2.  I have a TemplateField for my GridView that combines the first name and last name with Eval()'s, but the GridView places this combined field TemplateField and puts it as the first column.

How can I do this so that TemplateField can go in between fields that are databound?  Thanks in advance. :)

store textbox(inside the gridview) information in single variable".


Hi Friends.
Im using gridview. It contain Name, Sex, Mobile and Message
That Message details have to display in textbox(Inside the GridView),
Now I want store textbox information in single variable".

read 3 Three tables and display correspond value on a single grid


I have 3 tables in single database with different strctures,3 tables have unique column(partno or Jobno) , on web form search button input control(textbox) and grid view.I am pulling the data based on column jobno from single table on to grid view using following code

 VB.Net Code

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
            Dim connectionString As String = "Database=Job;" & "Data Source=localhost;" & "User Id=root;Password=XXX"
            Dim query As String = "SELECT * FROM ship where PacklistNo='" + txtSearch.Text + "'"
            Dim connection As New MySqlConnection(connectionString)
            Dim da As New MySqlDataAdapter(query, connection)
            Dim ds As New DataSet()
            If da.Fill(ds) Then
                dgResults.DataSource = ds.Tables(0)
            End If
        Catch ex As Exception
        End Try
    End Sub
If user types Jobno-123 click on search button it should read all the 3 tables in a database and display corresponding value on grid 

update two tables from single grid view using stored procedure PLZ help


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace INV_DN
    public partial class Form1 : Form
        SqlConnection con;
        SqlDataAdapter da1;
        SqlCommand cmd;
        //  SqlCommandBuilder cb;
        DataSet ds;
        public Form1()

        private void Form1_Load(object sender, EventArgs e)
            con = new SqlConnection("User Id=sa;Password=123;database=amar");
            cmd = new SqlCommand("getdata", con);

gridview boundfield


Hi Friends,

how to create calculated column using boundfield in gridview?

i want to create a new column using the existing records?

can help me?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend