.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 with null values

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

 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

View Complete Post

More Related Resource Links

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

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;

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

Help: Too many lines of code to achieve a simple goal: keep my NULL SQL values...


Hello all

What is the best way (best practice) to preserve my NULL SQL values in the database
during an insert/update operation (without receiving cast invalid errors)?
Also, how to display a string 'n/a' when a sql value is NULL?

My project is using FormView with Edit/Insert templates and classes to represent my tables

Goal1....: display 'n/a' when there are NULL SQL values in the database
Solution1: I am using ISNULL(field,'') in my store procedure for SELECT statements

Goal2....: if the fields are 'n/a', then save them back in the database as NULL
Solution2: on my insert/edit methods I am having to check the values being passed, i.e:

cmd.Parameters.Add(new SqlParameter("@scope", SqlDbType.NVarChar, 50));

if (item.Scope == "n/a")
 cmd.Parameters["@scope"].Value = DBNull.Value;
 cmd.Parameters["@scope"].Value = item.Scope;

Not to mention that for SQL DateType fields when you use ISNULL(field,'') the return string is '1/1/1900 12:00:00 AM'
and I have to change the field value in every field that represents a date, i.e:

protected void FormView1_DataBound(object sender, Sy

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

how do i use javascript to change values of controls inside a gridview

i have 2 labels (lblRate,lblTotal) and a textbox (txtQuantity) in a itemtemplate of a gridview.I want to calculate the products of rate and quantity and show it in Total as the textbox loses focus...i cant use textchanged because i dont want the page to postback.How do i use javascript to achieve this??Please Help Urgently....<asp:TemplateField HeaderText="Rate">                <ItemTemplate>                    <asp:Label ID="lblRate" runat="server" Text='<%# Eval("Rate") %>' />                </ItemTemplate>            </asp:TemplateField> <asp:TemplateField HeaderText="Quantity">                <ItemTemplate>                    <asp:TextBox ID="txtQty" runat="server" />                </ItemTemplate>&

Accessing a row's dropdownlist values AFTER the gridview control is in Edit mode

Hello, I have a gridview control. When it goes into Edit mode, there are 3 dropdownlists in one cell that are populated by separate stored procedures during the RowDataBound event. The 1st dropdownlist's value is used as a parameter to determine what the 2nd dropdownlist is populated with. The 2nd dropdownlist's value is used as a parameter to determine what the 3rd dropdownlist is populated with. Everything works fine when the row is first put into Edit mode. While I'm in Edit mode and I change the selection in the 1st dropdownlist, how do I access the control so I can feed this new parameter to the 2nd dropdownlist? I have the first 2 dropdownlists set for AutoPostBack so that the Page_Load event is fired when the user changes a value. I know how to get access to these controls via the FindControl method when the row is being databound but how do I find the control during the Page_Load event? Thanks for any help!!!   Penny  

SSRS Report based on SSAS Cubes doesn't show NULL values correctly

I have a SSRS report which is based on an SSAS Cube. In the Cube the formating of numeric fields that NULL values are properly shown as NULL values. In the Cube Browser and Excel this is shown correctly. However when I design the report already the query against SSAS shows these fields as "0" instead of NULL. Is there a way to fix this or is this a bug ?  

keep values in textbox in gridview whilst paging

Hi,   I have a gridview in my webpage which has paging enabled. There are around 5 textboxes in a row and when I enter some text and then move to another page and move back to the page I entered the values in, they are not lost. I have enabled the viewstate in the gridview. I have implemented a datatable to my grid which should hold the values in the viewstate. This worked before I added paging. Please can someone offer some advice as to how I can maintain the values in textboxes whilst moving between different pages? I have tried searching it but I can't seem to find any relevant info.   Thank you very much.

gridview values confusion

hi guysi have one page "Search" where the user can search based on the name of the customerI have another page that contains the details for that customermy question is that on the top of the second page i would like to have the name of the customer that the user search for.so the page would look like this                   JOHN JOHNSONDob    .......Tel ........etcwhen i try to create a gridview to bring the value of the name on the top of the page i get confused because the WHERE clause only allows me to select from textboxes included in that page and not on another pagehow can i overcome this?

Comparing Null Values(from variable) in SSIS

Hi All I need to create a script that checks to see if a variable value is NULL, if it is then it executes the next SQL Task and if not then the package has finished. I have this in a SQL 2000 DTS package script: Function Main() If isnull(DTSGlobalVariables("NextLoadDate")) Then Main = DTSStepScriptResult_DontExecuteTask Else Main = DTSStepScriptResult_ExecuteTask End if End Function As you can see, all I want to do is check to see if a variable is null then don't execute the next task. But i cannot get it to work in a SQL 2005 SSIS package, so far I have created a script and come up with the following: Public Sub Main() If Dts.Variables("NextLoadDate").Value.ToString <> "" Then Dts.TaskResult = Dts.Results.Success Else Dts.TaskResult = Dts.Results.Failure End If End Sub Any Ideas? Thanks BigGopher

Build xml file from gridview values on button click

We are looking to add GoogleMaps to our application. With that said we are going to be using the geocoding api to pass in the lat and long values to pin point locations on the the map. Reading thru the documentation we can pass in the values via XML, so we would like to see how we can take the lat and long values from our gridview and pass that to the API if and when somone clicks on the button to show the map.. The process will work like so, you arrive at the search page, you complete a search, in most if not all cases, you will always get multiple results presented in a gridview. If you should to view them all on the map, you click button and it needs to map out each location on the map. So is there anyway to pull from the gridview the lat, long and description to pass into the API?   Any links to sites that i can review would be great. thanks. 

Comparing columns with NULL values--Merge says unmatched when data is matched.

I found the article below describing this same issue with the Oracle merge statement.  It also described a work-around:    http://searchoracle.techtarget.com/tip/Merging-datasets-with-NULL-values I have been unable to find a solution to this issue for SQL Server 2008.  I am trying to do basic ETL from Staging table to a Type II dimension table in a Data Warehouse.  I am using the Merge statement with the Unique key minus the modification date as my merge key list.  I have a handful of columns (in both Staging and the DW) containing nulls in my merge key list.  I have tried the ISNULL function and the ANSI_NULL db option (OFF) with no success.  When I put zeros in the null columns, it works as expected.  I am about to try separate INSERT and UPDATE statements, but I fear that the NULL comparison issue will bite me there with the JOIN statement.  Has anyone else experienced this?  NULL values are valid in our Data Warehouse.  How can I make T-SQL handle them? Thank you for your help, Jesse
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