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

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Dynamic templatefield disappear during gridview rowcommand

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :ASP.Net
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? 

View Complete Post

More Related Resource Links

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.

Adding Dynamic Rows in GridView with TextBoxes

I decided to write this article because this has been asked so many times before at the forums(http://forums.asp.net) . Basically, this example shows on how to generate a Row in GridView with TextBoxes when clicking a Button that is residing inside a GridView Footer.

Adding Dynamic Rows in GridView with TextBoxex in C#

I decided to write this article because this has been asked so many times before at the forums(http://forums.asp.net) . Basically, this example shows on how to generate a Row in GridView with TextBoxes when clicking a Button that is residing inside a GridView Footer.

gridview help on each dynamic row solve this show values based on all columns

<asp:GridView style="Z-INDEX: 101; LEFT: 1px; POSITION: absolute; TOP: 183px" id="Gridview1" runat="server" Width="613px" Height="127px" ForeColor="Teal" Font-Size="12pt" Font-Names="Palatino Linotype" Font-Bold="True" Visible="False" BorderColor="Transparent" AutoGenerateColumns="false" CellSpacing="2" GridLines="None" OnRowCreated="Gridview1_RowCreated" SelectedIndex="5" ShowFooter="true" OnRowDataBound="Gridview1_RowDataBound"><Columns>  <asp:TemplateField HeaderText="ItemCode"><ItemTemplate> <asp:DropDownList id="DropDownList1" tabIndex=16 runat="server" AutoPostBack="True" DataValueField=" ItemCode " DataTextField=" ItemCode" ></asp:DropDownList></ItemTemplate></asp:TemplateField>  <asp:TemplateField HeaderText="ItemName"><ItemTemplate> <asp:DropDownList id="DropDownList2" tabIndex=16 runat="server" AutoPostBack="True" DataValueField="ItemName" DataTextField="ItemName" ></asp:DropDownList> </ItemTemplate> </asp:TemplateField>  <asp:TemplateField HeaderText="Category"&

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 

RowCommand not firing inside a GridView

Hello,  I'm trying to fire the RowCommand event on a DataGrid control.  I've previously done that, but not in this precise case.  Actually I'm working on someone else code so I can't really change the structure of his page excepted if it's really necessary. The code of the page is heavy, so I've summarized the problem in a small project and the page behaves the same way too.   Basically I have a GridView which I bind to a DataSet.  According to those data, I sometimes need to add, at the end of a row, a "Details" button (a LinkButton).  By pushing this button, I want to show a second GridView containing those details.  Let's add to this that the columns number of the first GridView is variable, those LinkButton need to be added dynamically.   The first GridView is generated without any problem and when my mouse is over one of the LinkButton, I can see that the link is something like "javascript:__doPostBack('dataGridView$ctl02$lnkDetail','')".  When I click on this link and debug step by step : Page_Init, Page_Load, OnPrerender, RowDataBound but no RowCommand, and I don't know why!   In the exemple, I've explicitly set the EnableViewState to true from what I've read here and there, but nothing's changed.   Here's my summarized problem and

Gridview RowCommand Event returning null values

HiI'm trying to retreive values entered by users in the textboxes in the footer of the gridview and insert these values into another sql table.My code is as follows :-protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)    {       if(e.CommandName.Equals("addnew"))       {                       TextBox t1 = (TextBox)GridView2.FooterRow.FindControl("tfrm");            string frm = t1.Text;            TextBox t2 = (TextBox)GridView2.FooterRow.FindControl("tsub");            string sub = t2.Text;            string cmd = "insert into suggestions values('" + frm + "','" + sub + "','c','c')";            con.Open();            SqlCommand com = new SqlCommand(cmd,con);            int a = com.ExecuteNonQuery();&n

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 Image Buttons in GridView not doing partial post back

Hi Gurus - Create a gridview with AllowPaging and AllowSorting = true- On page load, I bind it to datasource (in my case a webservice) - On gridview's rowcreated event, I dynamically add image buttons on the header of the grid for sorting (up/down arrows). On header I have column name and the image. I removed the Column name default sorting link. So user can now only click the image button for sorting.-  Call sorting method This works perfectly fine without AJAX. The paging, sorting works fine. Also when I apply AJAX the paging works fine. But the sorting is doing a full post back instead of partial postback. I have my gridview within UpdatePanel and Triggeres is set on gridview sill it doesn't work.ASPX Code<form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <asp:Label ID="lblAccount" runat="server" Text="Account #: "></asp:Label> <asp:TextBox ID="txtAccountNumber" runat="server">12203A30</asp:TextBox> <asp:Button ID="cmdGo" runat="server" Text="Go" OnClick="cmdGo_Click" /><br /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> &l

1st PostBack only: SelectedIndexChanged events fire AND GridView & ReadOnly controls disappear

On initial load of the page, everything is visible & runs correct. On the first PostBack fired by any one of my DDLs, RadioBtns, LinkBtns that have the AutoPostBack=true property, then ddlPriority_SelectedIndexChanged & ddlPendUserReqType_SelectedIndexChanged events always fire (and only from these DDLs, the others don't fire inappropriately), even when neither of those controls had been selected. Then my GridView gridPendRoles disappears, unless a DataSource & DataBind() is forced. Any ReadOnly controls (lblTicketID, txbxInsertTicketDate, lblPendUserID) will also loose their data/text in the first PostBack. However, every PostBack following will not inappropriately fire events. And as long as a DataSource was set & DataBind() called a 2nd time at any time during any PostBack, the GridView will stay visible with correct data displayed. Again, as long as the ReadOnly controls have their data/text set a 2nd time during any PostBack, they too will retain their data/text for every following PostBack. I've tried debugging with Trace on & walked thru everything very thoroughly, but still cannot catch any reasons why this would occur. And since I am using the Delete & Edit command linkBtns in my GridView, I can't just force a DataSource & DataBind() on every PostBack, or I would loose those Row

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?    

Creating dynamic template columns in gridview

how to create dynamic template columns in gridview  . I have writing some of the code but it gives me error The type or namespace name 'GridViewLabelTemplatecould' not be found (are you missing a using directive or an assembly reference?)    I have paste some my code /con.Open();        string strsql = "select ID,CompanyName from tblcompany";               SqlCommand cmd = new SqlCommand();        cmd.CommandType = CommandType.Text;        cmd.CommandText = strsql;        cmd.Connection = con;        SqlDataAdapter adpt = new SqlDataAdapter();        adpt.SelectCommand = cmd;        adpt.Fill(dt);        GridView1.Columns.Clear();        for (int i = 0; i < dt.Columns.Count; i++)        {            TemplateField tf = new TemplateField();            // create the data rows       

What's the difference between a dynamic data project and adding a gridview to a "normal" project?

Hi,I'm having difficulty understanding what dynamic data actually is.There is an option to specifically create a dynamic data project, but I don't understand the difference between this, and just adding some kind of data control, like a gridview or detailsview for example.If someone can help me understand this better I'd really appreciate it.

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. :)

run javascript after gridview rowcommand has been executed


I want to run some javascript after a rowcommand has been executed.

I tried this, but its not working

Protected Sub gvSearchResults_OnRowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvSearchResults.RowCommand
    Dim sb As New StringBuilder
    sb.Append("document.getElementById('" + Me.Master.CompareURL.ClientID.ToString + "').value='LALALAL';")
    Me.Page.ClientScript.RegisterStartupScript(Me.[GetType](), "test", sb.ToString(), True)
End Sub

gridview.rowcommand + sqldatasource.delete()


I have gridview+sqldatasource. In gridview i have button DELETE. But i want on click this button for some rows execute DELETE command other rows UPDATE. I did:

protected void GridMain_RowDataBound(object sender, GridViewRowEventArgs e)
  if (e.Row.RowType == DataControlRowType.DataRow)
     if (DataBinder.Eval(e.Row.DataItem, "DelFlag").ToString() == "True")
               btnDelete.CommandName = "Delete";
               btnDelete.CommandName = "DeleteVirtual";

protected void GridMain_RowCommand(object sender, GridViewCommandEventArgs e)
        if (e.CommandName == "Delete")
           sourceMain.DeleteCommand = "DELETE FROM [Main] WHERE 
        else if (e.CommandName == "DeleteVirtual")
            sourceMain.DeleteCommand = "UPDATE [Main] SET DelFlag = 'True' WHERE  
@index - DeleteParametrs in sqldatasource. But DELETE works and DELETEVIRTUAL doesn't. Then i insert sourceMain.Delete() in rowcommand after sourceMain.DeleteCommand ... But it's doesn't help m

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


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">
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