.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

ButtonText value (GridView) in PageLoad Event

Posted By:      Posted Date: September 12, 2010    Points: 0   Category :ASP.Net
I have a grid view,with last column a template field with a button. This GridView is Bound to a table in my Database. One of the columns in my Table has values "A" and "D". Based on this values I want the Button TextValue. For example, If the value is "A" the buttonText value should be "Deactivate" and if the value is "D" the buttonText value should be "Activate". All this I want to achieve in my Page Load Event? Any help would be appreciated?Dear Friends,I have a grid view,with the last column a template field with a button.This GridView is Bound to a table in my Database. One of the columns in my Table has values "A" and "D". Based on this values I want the Button TextValue.For example, If the value is "A" the buttonText value should be "Deactivate" and if the value is "D" the buttonText value should be "Activate".All this I want to achieve in my Page Load Event?Any help would be appreciated?

View Complete Post

More Related Resource Links

determine the best way to refresh a gridview when textchanged event occurs


Good afternoon.

I have the following gridview inside an updatepanel that makes the bind from a datatable:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <asp:Button ID="ButtonAdd" runat="server" OnClick="ButtonAdd_Click" Text="Novo Artigo" />
                <asp:GridView ID="Dados" runat="server" AutoGenerateColumns="False" 
                    CssClass="Grid" Width="100%" CellPadding="4" ForeColor="#333333" 
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                        <asp:Button ID="AbrirModal" runat="server" Text="->" /> 
                                <asp:PopupControlExtender ID="PopupControlExtender1" runat="server"

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 .

gridview tablecell text emptystring in RowDataBound event when editing


HI and thanks in advance.  asp.net using vb, using a codebehind page.

I have a relatively simple gridview bound to an product table that displays great.  The problem comes when I choose to edit a row.  When I do so, the gridviews' RowDataBound event fires and the values of the text properties of the tablecells in the row evaluate to "" emptystring. 

I do notice that if I break within the GridView1_RowDataBound event during a refresh of the page, the values are there.  But again, when I hit the "Edit" button in the first column (the CommandField column) .  Text properties of the cells resolve to ""

 Here is the code for the event, followed by the gridview in the form (inside an updatepanel)

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then  ' not a header, footer row.. etc.
            Dim cellProductNumber As TableCell = e.Row.Cells(3) ' ProductNumber column

'>>>>> after clicking "update", even though a value displays in the gridview,
' the cellProductNumber.Te

How to get object from the gridview selectindex changing Event.


I have a grid view which is populating with a data source through databind. And the Datasource is list of objects.Now when the user selected a row I want to get the object of that row.

I'm trying to get the row like this.


r = gvTruckCarrier.Rows[e.NewSelectedIndex];


drv = r.DataItem as DataRowView




but the drv value is

Can't change Gridview row colors or styles in the DataBound event


I was highlighting certain rows in my gridview using code like this in the DataBound event:

        if (e.Row.RowType == DataControlRowType.DataRow)
            int vendorCheck = 0;
            //TODO make this shorter
            if (DataBinder.Eval(e.Row.DataItem, "vendorId") != System.DBNull.Value)

GridView RowUpdating event

Hi,I have a gridview. In the rowupdating event, the txtbox returns null. I have enabled viewstate for the gridview. But still it does not work. I have made this in Kentico. Please help.<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"        AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1" EnableModelValidation="True"        OnRowUpdating="GridView1_RowUpdating" >        <Columns>            <asp:CommandField ShowDeleteButton="True" CausesValidation="false" ShowEditButton="True"                ControlStyle-Width="100px" />            <asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderText="Name" SortExpression="name">                <ItemTemplate>                    <as

Textchange Event in Gridview

frends, <asp:GridView ID="grideviewsasmple" runat ="server" AutoGenerateColumns ="false" AutoGenerateEditButton ="true" OnPageIndexChanging ="PageChange" OnRowEditing ="Edit" CellSpacing ="2" OnRowUpdating ="Update" OnRowCancelingEdit ="Cancel" DataKeyNames ="Sno" > <Columns > <asp:TemplateField > <HeaderTemplate > <asp:Button ID="buttonDelete" runat ="server" Text ="Delete" onclick="buttonDelete_Click" /> </HeaderTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Roles"> <HeaderTemplate> <asp:CheckBox ID="chkAll" OnClick="javascript:SelectAllCheckboxesSpecific(this);" runat="server" /> </HeaderTemplate> <ItemTemplate>

how to use nested gridview's rowupdating event

Hi all,            I have a GridView within a GridView. I want o access child gridview's rowupdating event. i want to update row.            this is my GridView's code as follows<asp:GridView ID="grdv1" runat="server" AutoGenerateColumns="false" EmptyDataText="No records found" OnRowDataBound="grdv1_RowDataBound" CellPadding="0" Width="500px" CellSpacing="0" BorderWidth="0"> <Columns> <asp:TemplateField> <ItemTemplate> <table width="100%"> <tr> <td align="center"> <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>' CssClass="nbdcontent"></asp:Label> </td> </tr> <tr> <td style="height: 150px"> <asp:GridView ID="grdv2" runat="server" AutoGenerateColumns="False&

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 edit mode - What event does enter key call?

I have sort of a very specific problem.  I have a gridview with a few different template columns and a commandfield with the standard "edit" link.  There is no sqldatasource associated with it at all.  In the code, I pull some data from an sql database into a datatable and set the gridview's datasource to be the datatable.This all works fine.  When I hit the "edit" button, the standard textbox shows up where it needs to so that I can edit the data.  The problem is the updating portion.  I have programatically removed the "update" button and left the "cancel" button for design reasons. I want the user to be able to hit "enter" in order to update the data in the data table.  Then, when they're ready, they can click a submit button which will extract the data from the datatable and update the database.I'm having trouble with this 'enter key' business.  When you edit the data and hit "enter" while in edit mode, the page posts back, and the previous values are placed in the gridview.  What event was just  called?  I need a way to take what the user put in and place it in my datatable.  What are my options?Thank you. 

Checkbox checked changed event inside gridview

Hi All, In my gridview there are 8 checkboxex in each row : 'Sunday' to 'Saturday' and one for 'All'. If 'All' is checked in a particular row, all other checkboxes in that row should be checked instantly, and viserversa. Can i do this in checkbox checked_changed event, if so how do i access the current row of the gridview in the checked changed event? Thanks in advance

find the label control of gridview in save button event in C#

hi, every one..i want save the gridview in buttonsave event..here i wrote the code like thisfor (int i=0;i<gridview1.row.count;i++){label lbl=(label)gridview1.rows[i].findcontrol("lbl");Textbox txtname=(Textbox)gridview1.rows[i].findcontrol("txtname");}here i got the textbox value but am not getting label value how to get that label value..thanks in advance

Keeping Custom properties in GridView Added on OnRowDataBound Event While Sorting

All of my columns are bound in the Gridview. On OnRowDataBound event, I am adding some custom styles like underlines and colors to the text of the columns. Sorting of data is working fine but I am losing my custom styles when I sort. I am using the generic sorting code for the GridView. How I can keep my custom styles on sorting that I added during OnRowDataBound event.   Thanks for your help.

gridview and textbox changed event



i have a textbox changed event i am calling this event  when textbox  value changed.

this textbox is inside gridviews Itemtemplate

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowUpdating="Update_Schedule"
                    OnRowDeleting="Delete_Schedule" OnPageIndexChanging="OnPaging" OnRowEditing="Edit_Schedule"
                    OnRowCancelingEdit="CancelEdit" PageSize="10">
                                <asp:Label Text='<%# Eval("Title") %>' runat="server" ID="lbl1"></asp:Label>
                                <asp:TextBox ID="txtTitle" Text='<%# Eval("Title") %>' runat="server"></asp:TextBox>

Send values to parent window on gridview click event


Hello all,

I have a form, which contains 2 textboxes. When i click on the first textbox, i have to open a child window (tool), that contains a gridview control with 2 columns (corresponding to the 2 textboxes). When the user clicks on any row in the gridview, it should send back the 2 column values back to the parent window to the corresponding 2 textboxes. Can anyone help me on how do i achieve this?

I can open the child window and get back the values using window.opener method in JS. 

But can anyone help on how to bind the JS code to the onClick of every row in the gridview. How can i activate the OnClick event of every row/alternating row item of the gridview and bind the JS code and pass each column value to that JS method? The no of columns in the gridview can vary depending upon the data? So in that case, i have to have a collection to be passed to JS code that can contain n number of column values.

Please help.

gridview event


i have a gridview1 that has update button.

i have a row its edittemplate has a checkbox like this :

                                        <asp:TextBox ID="TextBox12" runat="server"
                                            Text='<%# Bind("DaytimePhoneNumber") %>'></asp:TextBox>
                                        <br />

GridView RowDeleting event fires twice !


I'm facing some annoying GridView behavior where it fires the RowDeleting event twice.

I'm doing the very normal (logical) steps for deleting a row from a GridView. Here is what I'm doing:

1- my test Page_Load  method

protected void Page_Load(object sender, EventArgs e)

	GridView1.DataSource = GetDataTable();
	// Note: GetDataTable() returns a non-null DataTable object.
	// Also the DataTable has more than 1 row
	// (i.e. everything is fine with the datatable)

2- the GridView has a Delete Command Field.

3- on tracing I've noticed my RowDeleting event gets fired twice! (also I used a static counter to see how many times the event gets fired when clicking on the GridView delete button, which was also confirmed it that it's counting 2 per each click).

Am I doing something wrong? please help


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