.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

Gridview RowCommand Event returning null values

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

View Complete Post

More Related Resource Links

spgridview RowDataBound event returning cell values as empty


i am working with SPGridView to display Announcements. User should be able to edit his own created Announcements.Remaining Items shouldnt be having edit option.

i created SPGridView Columns :

                SPBoundField Title = new SPBoundField();
                Title.HeaderText = "Title";
                Title.HeaderStyle.Font.Bold = true;
                Title.DataField = "Title";

                SPBoundField Description = new SPBoundField();
                Description.HeaderText = "Description";
                Description.DataField = "Description";


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.

RowCommand returns null value for controls which are not binded to Gridview source


I am tryting to reach controls in the gridview rows by RowCommand event. I can take values of controls which are binded to gridview source successfully . But for all other controls which is not binded to gridview returns NULL value. All controls run at server. Why is that?

Gridview with null values


 In a search by address page, I have two text boxes to enter street number and/or street name. User can enter both the values or any one and click Search button. The matching data will be in a grid below.

My problem: sometimes the Street number column has null values. In those cases if I search by a street name that does not has a street number, nothing was coming. So I have changed the query as follows:

SELECT     ChurchID, PK_ApplNo, ADDDTTM, ADDBY, MODDTTM, MODBY, AppDate, Applicant, StreetNumber, StreetName, MagisterialDistrict,
                      UndisturbedOpenSpace, RearYardFt, MaxApprovHeightFt, NumberofSeats, NumberofParkingSpaces, ChildCareCenterCCC, NoofStudentsinCCC, School,
                      NoofStudentsinSchool, NurserySchool, NoInNurserySchool, BZABOSAction, BZABOSHearing, StaffRecommendation, SubjectComment, DateofDecision,
                      CornerLot, DPZ_BZA_BOSActionComment, NumberofSeats / NumberofParkingSpaces AS Ratio
FROM         tb

SSIS_SQL2005_Sharepoint ListSource Adapter_DT_NTEXT values returning NULL on extract/import


Hello.  Please HELP!!!!  I've been trying to figure this out for a few days.

I am using the SSIS SharepointAdapters for 2005.  When I pull data from my sharepoint site, for fileds that are choice fields in sharepoint are a datatype of DT_NTEXT w/4000 characters.  The only thing in these fields is "PASS" " "FAIL" and one filed has "QA Review Completed".  When the data is imported into SQL these fields eiher show NULL or <Long Text>.  I am using the combination of the Derived Column and Data Conversion to change the Datatype of these fields from DT_NTEXT since no output will accept this datatype.  I've tried exporting to Excel, Access and Flat files only to get same results.  What I don't understand is if I import the data from Sharepoint to Access or Sharepont to Excel using Sharepoint and not SSIS, I get the data that is in the field(s).

I've searched all over the internet and have not found where anyone has had the same issue which I find to be odd - I can't be the only one.  I hope I'mnot.




Gridview Null all values , Javascript


I did following code in vb.aspx, how I do following code in Javascript script,

Gridview1.EmptyDataText = "Data Not Found !"
Thanks in advance.

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"

update parentpage gridview with the values from child page?


hi   i am having a gridview on each row i am having a update and add button.

on click of either of the button i am opening a popup where the end user will enter data and on clck of ok button in the child page

based on the click ie

if i clicked update i need to update that particular row with the values from child page.

if i clicked on add i need to add a row below the row where i clicked add button .

can anyone help me with this?

How to deal with NULL values in a SQL table


 Hi all

In order to add/update/delete data from a table I build 2 classes: 1 class containing all the table fields and another class with methods to add/insert/update/delete records. I am learning how to avoid errors when your table must use SQL NULL values. One error is when I call my UPDATE method (see below):

  public void UpdateItem(OcItemConstraintDetails item)
  SqlConnection con = new SqlConnection(connectionString);
  SqlCommand cmd = new SqlCommand("ItemConstraints_Update", con);
  cmd.CommandType = CommandType.StoredProcedure;

  cmd.Parameters.Add(new SqlParameter("@itemConstraintId", SqlDbType.Int, 4));
  cmd.Parameters["@itemConstraintId"].Value = item.ItemConstraintId;

  cmd.Parameters.Add(new SqlParameter("@path", SqlDbType.NVarChar, 150));
  cmd.Parameters["@path"].Value = item.Path;

if you watch the SQL profiler trace you will see that I am passing a value of 'default' ;so that causes me problems.

exec ItemConstraints_Update @itemConstraintId=1,@path=default

With that said, what are the best practices when your SQL table accepts NULL values and when:
- you are passing an empty value to your stored procedure;

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

Get values of row in a gridview


Hi everyone

I have a problem that can't find a way to do it, I have a gridview with this columns:

ID  |  AreaName  |  CostCenter

with the "Enable Editing" option check and what I want to do is to get the values of areaname and costcenter and assign them to a label control so I can use the values for something else, for example:

ID        AreaName       CostCenter

1          Multiconector   1025

2          One Conector   2065

3          Plug & Play       1445

hsdsd: how to insert two values from text box1 to gridview g



table a

a                                 b

jhgd                           kljhskjd

sdghdshgd                 jkhdjhdjk

what i need is when enter some values(varchar ) in txt 1 and 2

it should be added in database and shown in gridview1 after i press butt1


any bodyknows full code answer/akdj

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

How can I change values in mydetailsview_ ItemInserting event

I'm inserting values with detailsview, and I want to modify one of my values and my client should not see it.

This is my detailsview:

<asp:DetailsView ID="dv_InsertTaps" Runat="server" DataSourceID="ds_InsertTaps" DataKeyNames="TapId"
AutoGenerateRows="False" DefaultMode="Insert" title="INSERTAR TAPS" OnItemInserting="dv_InsertTaps_ItemInserting">
<asp:TemplateField SortExpression="TapNumero" HeaderText="N&#186; Tap"><InsertItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("TapNumero") %>' ID="tb_TapNumero"></asp:TextBox>
<asp:BoundField HeaderText="Valor" DataField="TapValor" SortExpression="TapValor"></asp:BoundField>
<asp:BoundField HeaderText="Alta Frecuencia" DataField="TapAF" SortExpression="TapAF"></asp:BoundField>
<asp:BoundField HeaderText="Baja Frecuencia" DataField="TapBF" SortExpression="TapBF&quo

Control Values When Returning to Page


Why do controls value not persist when returning to a page (e.g. via browser back button)?  If I set control values without utilizing a post back the controls will maintain their last value when I return to the page.  If I set a control value and then call a post back, the control value is reset to the default value when returning.

I have many pages with a gridview, and a textbox which is used to filter the gridview contents.  I set the filter textbox, filter the gridview (postback), go to another page, and when I return to the gridview page (via back button), my filter textbox is reset empty, and the gridview is the original (unfiltered) data.

What concept am I missing here?

Thanks in advance...

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