473,782 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDownList in editable DataGrid

Hi,
I¹ve tried to implement a solution to populate a dropdownlist inside an
editable datagrid. The code is simple enough and an example can be found
here: <http://www.4guysfromro lla.com/webtech/050801-1.shtml>
The problem I'm having is that the entire datagrid disappears after I click
the Edit link.
Could someone tell me what I'm doing wrong?
Much appreciated,
Stephan.

THE GRID:

<asp:DataGrid id="ByJob" AutoGenerateCol umns="false"
OnEditCommand=" ByJob_Edit" OnCancelCommand ="ByJob_Canc el"
OnUpdateCommand ="ByJob_Upda te" DataKeyField="P ersonID" runat="server">
<HeaderStyle backcolor="Blac k" forecolor="Whit e" font-bold="True"
horizontalalign ="Left" />
<AlternatingIte mStyle BackColor="#DED CFF" />
<Columns>
<asp:EditComman dColumn EditText="Edit"
CancelText="Can cel"
UpdateText="Upd ate"
ItemStyle-Wrap="false"
/>
<asp:TemplateCo lumn HeaderText="Nam e">
<ItemTemplate >
<asp:Label ID="NameLabel" runat="server"
Text='<%# DataBinder.Eval (Container.Data Item, "Name") %>'></asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:DropDownLi st id="NameEdit"
DataValueField= "PersonID" DataTextField=" Name" DataSource="<%# TempDataView
%>" runat="server"> </asp:DropDownLis t>
</EditItemTemplat e>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>

THE CODE BEHIND:

public virtual void Page_Load (Object Sender, EventArgs e) {

if (! Page.IsPostBack ) {
Defaults (); //Defaults runs a SQL query that populates the
datagrid. That part works fine (not shown)
}
}

protected void PopulateDropDow nList () {
try {
String ShowPeople = "SELECT * FROM People";
SqlConnection myConnection = new SqlConnection(" server =
'LMM-MB-DATA,25886';Dat abase = 'LMM_Jobs'; Trusted_Connect ion=Yes");
SqlDataAdapter myCommand = new SqlDataAdapter( ShowPeople,
myConnection);

DataSet ds_Names = new DataSet();
myCommand.Fill( ds_Names, "People");
DataView TempDataView = new DataView(ds_Nam es.Tables["People"]);
//DataBind();
}
catch (Exception SQL) {
SqlError.Text = "<strong><cente r><font color = red>Sorry, there
was a problem with the database connection. Please try again
later</center></strong></font><br>" +
SQL.Message;
}
}

protected void ByJob_Edit (object sender, DataGridCommand EventArgs e) {
PopulateDropDow nList ();
ByJob.EditItemI ndex = e.Item.ItemInde x;
}

Nov 18 '05 #1
2 1614
Try calling the PopulateDropDow nList () method after setting the
EditItemIndex

"Stephan Bour" <sb***@niaid.ni h.gov> wrote in message
news:BC453055.E B30%sb***@niaid .nih.gov...
Hi,
I¹ve tried to implement a solution to populate a dropdownlist inside an
editable datagrid. The code is simple enough and an example can be found
here: <http://www.4guysfromro lla.com/webtech/050801-1.shtml>
The problem I'm having is that the entire datagrid disappears after I click the Edit link.
Could someone tell me what I'm doing wrong?
Much appreciated,
Stephan.

THE GRID:

<asp:DataGrid id="ByJob" AutoGenerateCol umns="false"
OnEditCommand=" ByJob_Edit" OnCancelCommand ="ByJob_Canc el"
OnUpdateCommand ="ByJob_Upda te" DataKeyField="P ersonID" runat="server">
<HeaderStyle backcolor="Blac k" forecolor="Whit e" font-bold="True"
horizontalalign ="Left" />
<AlternatingIte mStyle BackColor="#DED CFF" />
<Columns>
<asp:EditComman dColumn EditText="Edit"
CancelText="Can cel"
UpdateText="Upd ate"
ItemStyle-Wrap="false"
/>
<asp:TemplateCo lumn HeaderText="Nam e">
<ItemTemplate >
<asp:Label ID="NameLabel" runat="server" Text='<%# DataBinder.Eval (Container.Data Item, "Name") %>'></asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:DropDownLi st id="NameEdit"
DataValueField= "PersonID" DataTextField=" Name" DataSource="<%# TempDataView %>" runat="server"> </asp:DropDownLis t>
</EditItemTemplat e>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>

THE CODE BEHIND:

public virtual void Page_Load (Object Sender, EventArgs e) {

if (! Page.IsPostBack ) {
Defaults (); //Defaults runs a SQL query that populates the
datagrid. That part works fine (not shown)
}
}

protected void PopulateDropDow nList () {
try {
String ShowPeople = "SELECT * FROM People";
SqlConnection myConnection = new SqlConnection(" server =
'LMM-MB-DATA,25886';Dat abase = 'LMM_Jobs'; Trusted_Connect ion=Yes");
SqlDataAdapter myCommand = new SqlDataAdapter( ShowPeople,
myConnection);

DataSet ds_Names = new DataSet();
myCommand.Fill( ds_Names, "People");
DataView TempDataView = new DataView(ds_Nam es.Tables["People"]); //DataBind();
}
catch (Exception SQL) {
SqlError.Text = "<strong><cente r><font color = red>Sorry, there was a problem with the database connection. Please try again
later</center></strong></font><br>" +
SQL.Message;
}
}

protected void ByJob_Edit (object sender, DataGridCommand EventArgs e) { PopulateDropDow nList ();
ByJob.EditItemI ndex = e.Item.ItemInde x;
}

Nov 18 '05 #2
Sorry, no change. I need to amend the original statement though. The
datagrid is now reloaded as is instead of disappearing. The "Edit" link is
still present and does not change to the expected Update and Cancel links.

in article #a************* *@tk2msftngp13. phx.gbl, Janaka at
ja****@magicali a.com wrote on 2/3/04 12:02 PM:
Try calling the PopulateDropDow nList () method after setting the
EditItemIndex

"Stephan Bour" <sb***@niaid.ni h.gov> wrote in message
news:BC453055.E B30%sb***@niaid .nih.gov...
Hi,
I¹ve tried to implement a solution to populate a dropdownlist inside an
editable datagrid. The code is simple enough and an example can be found
here: <http://www.4guysfromro lla.com/webtech/050801-1.shtml>
The problem I'm having is that the entire datagrid disappears after I

click
the Edit link.
Could someone tell me what I'm doing wrong?
Much appreciated,
Stephan.

THE GRID:

<asp:DataGrid id="ByJob" AutoGenerateCol umns="false"
OnEditCommand=" ByJob_Edit" OnCancelCommand ="ByJob_Canc el"
OnUpdateCommand ="ByJob_Upda te" DataKeyField="P ersonID" runat="server">
<HeaderStyle backcolor="Blac k" forecolor="Whit e" font-bold="True"
horizontalalign ="Left" />
<AlternatingIte mStyle BackColor="#DED CFF" />
<Columns>
<asp:EditComman dColumn EditText="Edit"
CancelText="Can cel"
UpdateText="Upd ate"
ItemStyle-Wrap="false"
/>
<asp:TemplateCo lumn HeaderText="Nam e">
<ItemTemplate >
<asp:Label ID="NameLabel"

runat="server"
Text='<%# DataBinder.Eval (Container.Data Item, "Name") %>'></asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:DropDownLi st id="NameEdit"
DataValueField= "PersonID" DataTextField=" Name" DataSource="<%#

TempDataView
%>" runat="server"> </asp:DropDownLis t>
</EditItemTemplat e>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>

THE CODE BEHIND:

public virtual void Page_Load (Object Sender, EventArgs e) {

if (! Page.IsPostBack ) {
Defaults (); //Defaults runs a SQL query that populates the
datagrid. That part works fine (not shown)
}
}

protected void PopulateDropDow nList () {
try {
String ShowPeople = "SELECT * FROM People";
SqlConnection myConnection = new SqlConnection(" server =
'LMM-MB-DATA,25886';Dat abase = 'LMM_Jobs'; Trusted_Connect ion=Yes");
SqlDataAdapter myCommand = new SqlDataAdapter( ShowPeople,
myConnection);

DataSet ds_Names = new DataSet();
myCommand.Fill( ds_Names, "People");
DataView TempDataView = new

DataView(ds_Nam es.Tables["People"]);
//DataBind();
}
catch (Exception SQL) {
SqlError.Text = "<strong><cente r><font color = red>Sorry,

there
was a problem with the database connection. Please try again
later</center></strong></font><br>" +
SQL.Message;
}
}

protected void ByJob_Edit (object sender, DataGridCommand EventArgs e)

{
PopulateDropDow nList ();
ByJob.EditItemI ndex = e.Item.ItemInde x;
}



Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1730
by: Bill | last post by:
I have a seating chart web form that has over 50 entry field controls (tables/booths) where I use a DropDownList box to select a single company name from a single large list of organizations (200 plus conference attendees). All web form datavalues will be one of the same 200 organizations in this list. I would like to avoid creating 50 separate exact copies of the same DataSet object. Can you help? Q. Exactly how do I use the same...
0
272
by: anon | last post by:
Hi All, I have an editable datagrid in which one of the fields becomes a Drop dowl list in edit mode....i followed the example in the $ guysfrom rolla article http://www.4guysfromrolla.com/webtech/050801-1.2.shtml however one of them is not really populated from the database, and hence no need of a dataview...i would like to assign an array or arraylist alone to it, however it gives all sorts of errors....the code is as follows
5
1210
by: jack | last post by:
Hello, I have an Editable Datalist with a DropDownList. I can get the Get value, but can't Set the Current Value set to the value of the current Edited Item. Thanks, Jack
2
2347
by: Kay Chan | last post by:
Hi All, I am going to using a editable datagrid, one of the field should be a dropdownlist, here is my code <EditItemTemplate> <asp:DropDownList ID="INVESTMENT_FUND_ID" DataSource="<%# getINVESTMENT_FUND() %>" DataTextField="NAME" DataValueField="VALUE"
0
1833
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though it's a Sharepoint WebPart. I'm trying to do something fairly simple, create a datagrid that displays where and when a person works and allows them to change some of the information via DropDownLists. When the user clicks to edit a row, three of...
1
2369
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .. http://sf-f.org, weblog and search engine for fans and writers of
3
1792
by: Jeff | last post by:
I have added a dropdownlist to an editable datagrid to allow a user to select Yes or No: <ItemTemplate> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "reports") %>' ID="lblReports"/> </ItemTemplate> <EditItemTemplate> <asp:DropDownList runat="server" id="ddlReports"> <asp:ListItem value="Yes">Yes</asp:listItem>
0
1402
by: shamila.thakur | last post by:
I have an editable datagrid one of itz column is a dropdownlist <asp:TemplateColumn> <ItemTemplate> <asp:Label ID=lblAreaWebsiteID Runat=server text='<%# DataBinder.Eval(Container.DataItem,"WebsiteName")%>'></asp:Label> </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="ddlWebsiteName_edit" Runat=server
2
1732
by: Frank | last post by:
Hello, I am developing with VS.Net 2003 on the asp 1.1 platform. I am a few days new to using a datagrid. I found a nice tutorial and had no problems using an editable datagrid with textboxes and an additional buttoncolumn where I used a delete button to delete a specific row. Once I had finished that, I trnsformed the grid tso it will display a dropdownlist indtead of a textbox. After much grappling, I pretty much have
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10143
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.