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
it working except for one detail. Now, the delete function will not work
properly.
Following is the declaration of the grid in the .aspx page:
<asp:datagrid id=DGR_List runat="server" cellpadding="3"
oneditcommand=" DGR_List_Edit" oncancelcommand ="DGR_List_Canc el"
onupdatecommand ="DGR_List_Upda te" onitemcommand=" DGR_List_Comman d"
onitemdatabound ="DGR_List_Item DataBound" autogeneratecol umns="false">
<edititemstyl e forecolor="Maro on"></EditItemStyle>
<alternatingite mstyle backcolor="#B8C 6D4"></AlternatingItem Style>
<headerstyle font-bold="True" forecolor="Whit e"
backcolor="#336 598"></HeaderStyle>
<columns>
<asp:TemplateCo lumn HeaderText="Acc ounts">
<itemtemplate >
<asp:label id=Label4 runat="server" text='<%#
DataBinder.Eval (Container, "DataItem.Accou nt") %>'><!--use container because
the DGR is bound to the conatiner--></asp:label>
</ItemTemplate>
<edititemtempla te>
<!--this is a different data source...not what the dgr is bound
to-->
<asp:dropdownli st onselectedindex changed="Change _Cust_TB"
id=DropDownList 1 runat="server"
DataSource="<%# bizObj.Get_IB_A ccounts(IB_Acct )%>" DataTextField=" Account"
DataValueField= "Account" Width="100px" autopostback="T rue">
</asp:dropdownlis t>
</EditItemTemplat e>
</asp:TemplateCol umn>
<asp:BoundColum n DataField="Valu e" ReadOnly="True"
HeaderText="Val ue"></asp:BoundColumn >
<asp:BoundColum n DataField="Unit " ReadOnly="True"
HeaderText="Uni ts"></asp:BoundColumn >
<asp:EditComman dColumn ButtonType="Lin kButton" UpdateText="Upd ate"
HeaderText="Edi t Acct" CancelText="Can cel" EditText="Edit" >
<headerstyle wrap="False"></HeaderStyle>
<itemstyle wrap="False"></ItemStyle>
</asp:EditCommand Column>
<asp:ButtonColu mn Text="Delete" HeaderText="Del ete Acct"
CommandName="De lete">
<headerstyle wrap="False"></HeaderStyle>
<itemstyle wrap="False"></ItemStyle>
</asp:ButtonColum n>
</Columns>
</asp:datagrid>
When the Delete button is clicked, the onitemcommand event fires and
DGR_List_Comman d is called:
public void DGR_List_Comman d(Object sender, DataGridCommand EventArgs e)
{
switch(((LinkBu tton)e.CommandS ource).CommandN ame)
{
case "Delete":
Delete_Acct(e);
break;
default:
//do nothing
break;
}
}
And the function calls Delete_Acct(e):
public void Delete_Acct(Dat aGridCommandEve ntArgs e)
{
// e.Item is the table row where the command is raised. For bound
// columns, the value is stored in the Text property of a TableCell.
TableCell itemCell = e.Item.Cells[0];
string strCurrentAcct= itemCell.Text;
//call my own function to dlete item in first cell
bizObj.Delete_A cct(strListName , strCurrentAcct) ;
//do some more stuff and reload grid 2 1731
Frank,
Try
DropDownList ddk = (DropDownList) e.Item.Cells[X].FindControl("d dlId");
Another example:
TextBox tb = (TextBox)e.Item .Cells[5].FindControl("t xUserId");
HTH
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"Frank" wrote: 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 it working except for one detail. Now, the delete function will not work properly.
Following is the declaration of the grid in the .aspx page:
<asp:datagrid id=DGR_List runat="server" cellpadding="3" oneditcommand=" DGR_List_Edit" oncancelcommand ="DGR_List_Canc el" onupdatecommand ="DGR_List_Upda te" onitemcommand=" DGR_List_Comman d" onitemdatabound ="DGR_List_Item DataBound" autogeneratecol umns="false">
<edititemstyl e forecolor="Maro on"></EditItemStyle>
<alternatingite mstyle backcolor="#B8C 6D4"></AlternatingItem Style>
<headerstyle font-bold="True" forecolor="Whit e" backcolor="#336 598"></HeaderStyle>
<columns>
<asp:TemplateCo lumn HeaderText="Acc ounts">
<itemtemplate >
<asp:label id=Label4 runat="server" text='<%# DataBinder.Eval (Container, "DataItem.Accou nt") %>'><!--use container because the DGR is bound to the conatiner--></asp:label>
</ItemTemplate>
<edititemtempla te>
<!--this is a different data source...not what the dgr is bound to-->
<asp:dropdownli st onselectedindex changed="Change _Cust_TB" id=DropDownList 1 runat="server" DataSource="<%# bizObj.Get_IB_A ccounts(IB_Acct )%>" DataTextField=" Account" DataValueField= "Account" Width="100px" autopostback="T rue"> </asp:dropdownlis t>
</EditItemTemplat e>
</asp:TemplateCol umn>
<asp:BoundColum n DataField="Valu e" ReadOnly="True" HeaderText="Val ue"></asp:BoundColumn >
<asp:BoundColum n DataField="Unit " ReadOnly="True" HeaderText="Uni ts"></asp:BoundColumn >
<asp:EditComman dColumn ButtonType="Lin kButton" UpdateText="Upd ate" HeaderText="Edi t Acct" CancelText="Can cel" EditText="Edit" >
<headerstyle wrap="False"></HeaderStyle>
<itemstyle wrap="False"></ItemStyle>
</asp:EditCommand Column>
<asp:ButtonColu mn Text="Delete" HeaderText="Del ete Acct" CommandName="De lete">
<headerstyle wrap="False"></HeaderStyle>
<itemstyle wrap="False"></ItemStyle>
</asp:ButtonColum n>
</Columns>
</asp:datagrid> When the Delete button is clicked, the onitemcommand event fires and DGR_List_Comman d is called:
public void DGR_List_Comman d(Object sender, DataGridCommand EventArgs e)
{
switch(((LinkBu tton)e.CommandS ource).CommandN ame)
{
case "Delete":
Delete_Acct(e);
break;
default:
//do nothing
break;
}
} And the function calls Delete_Acct(e):
public void Delete_Acct(Dat aGridCommandEve ntArgs e)
{
// e.Item is the table row where the command is raised. For bound
// columns, the value is stored in the Text property of a TableCell.
TableCell itemCell = e.Item.Cells[0];
string strCurrentAcct= itemCell.Text;
//call my own function to dlete item in first cell
bizObj.Delete_A cct(strListName , strCurrentAcct) ;
//do some more stuff and reload grid
.
.
LoadData();
}
} This code worked fine until I added the dropdownlist. Now, in the Delete_Acct function, I cannot get a value from the first cell, which is where the droplist is.
I can get values into the variable strCiurrentAcct if I change TableCell itemCell = e.Item.Cells[0];
to TableCell itemCell = e.Item.Cells[1];
or TableCell itemCell = e.Item.Cells[2];
these cells contain no text boxes nor droplists. I tried doing a
if(e.Item.ItemT ype == ListItemType.Ed itItem)
{
// get value
}
but the this code doesn't get hit when I debug. The e.Item.ItemType is recognised as a TableRow Any suggestions? Thanks in advance,
Frank
Peter,
Thanks for the reply. I appreciate your time. I tried your suggestion
but had no luck. I ended up splitting the task into two pages, where I
perform the delete functionality on another page. There, I simply create
another grid without the droplist, load it with data, and then allow
users to delete. I am sure there is a better way, but am short on time.
Thanks,
Frank
*** Sent via Developersdex http://www.developersdex.com *** This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kevin Pedersen |
last post by:
Hello, I am using an editable datagrid. After I save the changes the
datagrid shows the old values.
I've read the posts about the Page_Load and not binding the datagrid
each time. The SQL that is being sent to the database is correct and
the changes are eventually being made. If I refresh the page after the
update then the new values appear.
I noticed that when I put a breakpoint in my update handler everything
works fine. When I take...
|
by: Stephan Bour |
last post by:
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.4guysfromrolla.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.
|
by: zambizzi |
last post by:
....I can't seem to get my hands on a control I'm loading in an editable
datagrid.
Here's my datagrid control:
<asp:datagrid
id="GLRulesGrid"
runat="server"
autogeneratecolumns="False"
oneditcommand="GLRulesGrid_Edit"
|
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
|
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...
| |
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,...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |