Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 3rd, 2005, 07:30 AM
Authorized User
 
Join Date: Jun 2003
Location: Indore, M.P., India.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to sandeep
Default DataGrid Problem

Hi!
    I am having a datagrid whose ItemTemplate looks like the following:

<asp:TemplateColumn HeaderText="Supervisior">

<ItemTemplate>
    <%# DataBinder.Eval(Container.DataItem,"SupName")%>
</ItemTemplate>

<EditItemTemplate>

<asp:DropDownList ID="drpReportsTo" DataTextField="Name" DataValueField="EmployeeID" DataSource = '<%# GetEmployees() %>'
SelectedIndex = '<%# GetSelEmployee((int)DataBinder.Eval(Container.Data Item,"ReportsTo")) %>' Runat = "server">
</asp:DropDownList>

</EditItemTemplate>

</asp:TemplateColumn>

When i click the edit button in the datagrid I am passing the value of ReportsTo to GetSelEmployee() function in code behind so that the dropdownlist in the EditItemTemplate selects the appropriate Item. My problem is that in the database the ReportsTo column can be null. If that happens the code : ((int)DataBinder.Eval(Container.DataItem,"ReportsT o")) produces an error as it is not able to convert null to int. Can anyone let me know how i can check if ReportsTo is not null and only then run

SelectedIndex = '<%# GetSelEmployee((int)DataBinder.Eval(Container.Data Item,"ReportsTo")) %>'

Thanks in advance!

Regards
Sandeep Saran
Reply With Quote
  #2 (permalink)  
Old June 3rd, 2005, 09:18 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'd recommend creating a helper function in the page. Have it check the value and return something appropriate.

protected int GetIndex(object value){
  if(value == DBNull){
    return -1;
  } else {
    return (int)value
  }
}

Call that from the data binding:

SelectedIndex = '<%# GetSelEmployee(GetIndex(DataBinder.Eval(Container. DataItem,"ReportsTo"))) %>'

-Peter
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with datagrid Shishir ASP.NET 1.0 and 1.1 Professional 1 January 6th, 2007 09:01 AM
Datagrid Problem monika.vasvani ASP.NET 1.0 and 1.1 Professional 1 December 5th, 2006 03:09 AM
DataGrid Problem anujrathi VB.NET 2002/2003 Basics 2 June 15th, 2006 02:18 AM
DataGrid Problem anujrathi ASP.NET 2.0 Basics 1 June 12th, 2006 03:52 PM
Datagrid problem dotnetprogrammer VS.NET 2002/2003 1 February 17th, 2005 05:11 AM



All times are GMT -4. The time now is 02:20 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.