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


Top 5 Contributors of the Month
Shivakumaran
hoangnganvy1993
Post New Web Links

Gridview SelectedIndexChanged on a dynamically created gridview

Posted By:      Posted Date: November 04, 2010    Points: 0   Category :ASP.Net
 

my html page is basically a panel

Programmatically i've created the entire page adding controls to the panel. I have a dynamically created Accordion and within each accordion pane i have a dynamic gridview based on the properties for the accordion pane. Each row within the GridView i have a Button with the CommandName of Select, with this i want to open a new window and go to a new URL with the properties in a BoundField. On postback i want to be able to return to the Accordion.SelectedIndex. 

The problem is i can't seem to use a findControl to capture the index of either the GridView or Accordion. Below is my code:

AjaxControlToolkit.Accordion accordion = new AjaxControlToolkit.Accordion();
        accordion.ID = "Accordion2";
        accordion.HeaderCssClass = "accordionHeader";
        accordion.ContentCssClass = "accordionContent";
        accordion.HeaderSelectedCssClass = "accordionHeaderSelected";
        accordion.FramesPerSecond = 100;
        accordion.TransitionDuration = 100;
        accordion.FadeTransitions = true;
        accordion.EnableViewState = true;
        if (Session["myAccordion.SelectedIndex"] != null)
        {
            accordion.SelectedIndex = (int)Session["myAccordion.SelectedIndex"];
        }

        Data


View Complete Post


More Related Resource Links

how to apply validation controls on Gridview which is created dynamically

  
 hi, i created a gridview with two columns and 8 rows dynamically. All the rows are empty and editable at runtime. I am giving column names for this grid from some other .aspx page by passing column names using querystring.Because i am using this grid for three different pairs of column names.  i would like to know how to apply Required Field Validator, Regular Expression Validator  and Range Validator on Gridview textboxes. So that by using those validators i want to validate user inputs. And i would also like to know how to add rows at runtime for this grid. I am using ASP.net 2.0 and C#.net for this.(Visual Studio 2005) The code i am using to create gridview is below. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoadData.aspx.cs" Inherits="LoadData" %>  <form id="form1" runat="server">  <div> <asp:GridView ID="GrdDynamic" runat="server" AutoGenerateColumns="False" ForeColor="#333333" BorderColor="GradientInactiveCaption" BorderStyle="Solid" style="z-index: 108; left: 24px; position: absolute; top: 13px">  <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />  <RowStyle BackColor="#EFF3FB"

Tricky Insert Logic for dynamically created row in GridView.

  

Hi, and thanks for peeping the query i have.

I am dynamically generating the Row in GridView and saving the data in database using StringCollection. Instead of using StringCollection i want to pass the data(user entered data) to local variable , eg:

string name = txtFName; and so on. but it wont work for dynamically created rows.

So if you knw how to assign the user provided data in the local variable like above i have show, please help me out. 

The code for inserting the records for dynamic created rows in grid view via StringCollection is below

code:

protected void btnSave_Click(object sender, EventArgs e)

{

        int rowIndex = 0;

        StringCollection sc = new StringCollection();

        if (ViewState["CurrentTable"] != null)

        {

            DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];

            if (dtCurrentTable.Rows.Count > 0)

         

Gridview Paging with Dynamically created Gridview in VB.NET

  

Hi,

I have a page that I am creating 5 separate GridViews on, depending on the button the user clicks, a different GridView will show up. On a few of the GridView's there is a need for paging, so in the CodeBehind I did the following


            billingGridView.ID = "BillingGridView"
            billingGridView.DataSource = sdsBilling
            billingGridView.AutoGenerateColumns = False
            billingGridView.AllowPaging = True



            billingGridView.ID = "BillingGridView"
            billingGridView.DataSource = sdsBilling
            billingGridView.AutoGenerateColumns = False
            billi

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 .


Dynamically creating Gridview Template - Linkbutton Click not working

  

Hi, 

I have written some code to dynamically generate template columns for gridview which works well. However, each cell in the gridview has to be a linkbutton, which when clicked does a db update and redirects to a specific url with some parameters in it.

I have attached a click event handler to the linkbutton in the InstantiateIn method but the event does not seem to fire.

Could someone please help? the code is below -

//Dynamically creating the Grid


protected void btnAnalyze_Click(object sender, EventArgs e)
    {
       
            gvProjectedCPM.Columns.Clear();

How can i add a textbox into a GridView Cell dynamically and how can i retrieve entred data

  
Hey, i think that the the subject can explain what i need, it's about adding a TextBox control with the code behind into a GridView, and also about how can i retrieve entered data after submitting, im using C#,Thanks.

how to add textbox dynamically in a gridview

  
i have to create several textbox inside a gridview with its textboxid unique. can anyone tell me how to achieve this with a code in Asp.net 2.0 ?

How to fetch data from textbox dynamically in a gridview

  
How to fetch data from textbox inside a gridview

GridView EditTemplate DropDownLists' Loads fire before SelectedIndexChanged events on AutoPostBack=

  
My GridView allows EditTemplate but no DataSource in the aspx page. I set the DataSource & DataBind in code behind. My problem is with 2 of the 4 DropDownLists: they require AutoPostBack=true b/c the load of ddlDptmtGrid is dependant on the selection from ddlOrgGrid, and the load of ddlPosGrid is dependant on the selection from ddlDptmtGrid. The problem lies in that every postback calls each ddl's load & then the SelectedIndexChanged event, by this point the SelectedValue has been reset or wiped. And i can't use "if (!IsPostBack) { }" b/c the initial click of the lnkEditBtn is a postback & the DropDownLists don't even exist till in Edit Mode, so i need this initial load. But it appears on every postback all the controls in Edit mode are wiped & re-initialized, so it forces each DDL to be re-declared & re-loaded, but then the SelectedValue (which caused the postback) cannot be remembered?<asp:GridView ID="gridPendRoles" runat="server" CellPadding="5" AutoGenerateColumns="False" BackColor="#CCFFFF" BorderColor="Black" BorderStyle="Solid" onrowdeleting="gridPendRoles_RowDeleting" onrowediting="gridPendRoles_RowEditing" onrowcancelingedit="gridPendRoles_RowCancelingEdit" onrowupdating="gridPendRoles_RowUpdating"

disable autopostback of checkbox inside of GridView during SelectedIndexChanged of ListView

  
Hi, I hope my question is clear: I have a checkbox placed inside a gridview: <GridView><asp:TemplateField HeaderText="Driver">   <ItemTemplate>       <asp:CheckBox ID="CheckBoxDriver" AutoPostBack="true" OnCheckedChanged="GridView_Persons_SelectedIndexChanged" ValidationGroup='<%# Eval("ID") + "-" +((GridViewRow)Container).RowIndex %>' CssClass="CXDriver" runat="server" Checked='false' />   </ItemTemplate>       </GridView> For example: A listViewItem 1 has 3 drivers are checked, A listViewItem 2 has 2 drivers are checked. Therefore, if changing the selectedIndex of the list, the checkbox indexChanged event will be fired. How could I disable the autopostback of the checkbox during the listview item changed. Thanks in advance

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

Assign Value to DropDownList in GridView Dynamically

  
Hi, I got GridView with 2 columns both are Template field with drop down list. What I need to do is someting like when user select course 3/3A/2A/2B , the type column will auto select pratical option dynamically. When select RTT /FTT/BTT , the type column will select Theory option. Can someone tell me how to work on this thing. Thank you. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">  <Columns>  <asp:TemplateField HeaderText="Course">  <ItemTemplate>  <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">  <asp:ListItem>2A</asp:ListItem>  <asp:ListItem>2B</asp:ListItem>  <asp:ListItem Value="3">3</asp:ListItem>  <asp:ListItem>3A</asp:ListItem>  <asp:ListItem>BTT</asp:ListItem>  <asp:ListItem>RTT</asp:ListItem>  <asp:ListItem>FTT</asp:ListItem>  <asp:ListItem></asp:ListItem>  </asp:DropDownList>  </ItemTemplate>  </asp:TemplateField>  <asp:TemplateField HeaderText="Type">  <ItemTemplate>  <asp:DropDownList ID="DropDownList2" runat="server">  <asp

How to get Checkbox value created at runtime above gridview header

  

I have creted a checkbox for each column of grid at the top of the header in row created event. I need to check wheather checkbox is checked after button click event.

//Build custom header.

                GridView oGridView = (GridView)sender;
                GridViewRow oGridViewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
                TableCell oTableCell = new TableCell();

                //Add Staff_ID
                CheckBox chkStaffID = new CheckBox();
                chkStaffID.ID = "chkStaff_ID";
                chkStaffID.Text = "Hide";
                chkStaffID.CheckedChanged += new System.EventHandler(chkStaffID_CheckedChanged);
   &nb

Viewing columns in a gridview dynamically

  
I have two tables in my database, one for teachers and another for students. The students table has column for name, admission no., math's, English, computer, agric. Different teachers are responsible for each subject. I have a gridview that shows all the columns, but I want only the teacher responsible for each subject see the columns for Name, Adm_no and his subject only (e.g Agric teacher will only see d column for  Name, Adm_no & Agric) I'm using session as the parameter. 
Pls how do I go about this.
 
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            DataSourceID="SqlDataSource1" AutoGenerateColumns="False" CellPadding="4" 
            ForeColor="#333333" GridLines="None">
            <RowStyle BackColor="#EFF3FB" />
            <Columns>
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Adm_no" HeaderText="Adm_no" 
                    SortExpression="Adm_no" />
                <asp:BoundField DataField="Agric" HeaderText="Agric" SortExpres

Dynamically Adding button in GridView

  

Hello,

I am using the following to dynamically add button to the cell of gridview, condition is that if the value of the fourth column is empty, then in place of empty cell add the button. But nothing is happening.  I am making use of the following logic in  RowDataBound event in gridview.


protected void gdvEmployee_RowDataBound(object sender, GridViewRowEventArgs e)

for( int i=0;i<=dataSet.Tables[0].Rows.Count;i++ )
            {
                if (dataSet.Tables[0].Columns[3] == null)
                {
                    Button button = new Button();
                    button.Text = "ADD";
                   DataColumn dataColumn = new dataColumn();
     &

Display XML Data in GridView Dynamically

  

how to display data in gridview dynamically using code behind, if the xml data is available in string variable (i don't want to use xml file for carrying data). plz let me know as soon as possible


Dynamically adding a checkbox to a gridview in a webpart

  

I have a webpart with a gridview that I would like to add a checkbox column to. I have read through a few articles but have not found one that actually works. Any help would be greatly appreciated.

thanks,


Luis R. Lebron
Categories: 
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