473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Editable DataGrid with DropDownList Question

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_Cancel"
onupdatecommand="DGR_List_Update" onitemcommand="DGR_List_Command"
onitemdatabound="DGR_List_ItemDataBound" autogeneratecolumns="false">

<edititemstyle forecolor="Maroon"></EditItemStyle>

<alternatingitemstyle backcolor="#B8C6D4"></AlternatingItemStyle>

<headerstyle font-bold="True" forecolor="White"
backcolor="#336598"></HeaderStyle>

<columns>

<asp:TemplateColumn HeaderText="Accounts">

<itemtemplate>

<asp:label id=Label4 runat="server" text='<%#
DataBinder.Eval(Container, "DataItem.Account") %>'><!--use container because
the DGR is bound to the conatiner--></asp:label>

</ItemTemplate>

<edititemtemplate>

<!--this is a different data source...not what the dgr is bound
to-->

<asp:dropdownlist onselectedindexchanged="Change_Cust_TB"
id=DropDownList1 runat="server"
DataSource="<%#bizObj.Get_IB_Accounts(IB_Acct)%>" DataTextField="Account"
DataValueField="Account" Width="100px" autopostback="True">
</asp:dropdownlist>

</EditItemTemplate>

</asp:TemplateColumn>

<asp:BoundColumn DataField="Value" ReadOnly="True"
HeaderText="Value"></asp:BoundColumn>

<asp:BoundColumn DataField="Unit" ReadOnly="True"
HeaderText="Units"></asp:BoundColumn>

<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
HeaderText="Edit Acct" CancelText="Cancel" EditText="Edit">
<headerstyle wrap="False"></HeaderStyle>

<itemstyle wrap="False"></ItemStyle>

</asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" HeaderText="Delete Acct"
CommandName="Delete">

<headerstyle wrap="False"></HeaderStyle>

<itemstyle wrap="False"></ItemStyle>

</asp:ButtonColumn>

</Columns>

</asp:datagrid>

When the Delete button is clicked, the onitemcommand event fires and
DGR_List_Command is called:

public void DGR_List_Command(Object sender, DataGridCommandEventArgs e)

{

switch(((LinkButton)e.CommandSource).CommandName)

{

case "Delete":

Delete_Acct(e);

break;

default:

//do nothing

break;

}

}

And the function calls Delete_Acct(e):

public void Delete_Acct(DataGridCommandEventArgs 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_Acct(strListName, strCurrentAcct);

//do some more stuff and reload grid

Mar 9 '06 #1
2 1715
Frank,
Try

DropDownList ddk = (DropDownList) e.Item.Cells[X].FindControl("ddlId");

Another example:

TextBox tb = (TextBox)e.Item.Cells[5].FindControl("txUserId");

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_Cancel"
onupdatecommand="DGR_List_Update" onitemcommand="DGR_List_Command"
onitemdatabound="DGR_List_ItemDataBound" autogeneratecolumns="false">

<edititemstyle forecolor="Maroon"></EditItemStyle>

<alternatingitemstyle backcolor="#B8C6D4"></AlternatingItemStyle>

<headerstyle font-bold="True" forecolor="White"
backcolor="#336598"></HeaderStyle>

<columns>

<asp:TemplateColumn HeaderText="Accounts">

<itemtemplate>

<asp:label id=Label4 runat="server" text='<%#
DataBinder.Eval(Container, "DataItem.Account") %>'><!--use container because
the DGR is bound to the conatiner--></asp:label>

</ItemTemplate>

<edititemtemplate>

<!--this is a different data source...not what the dgr is bound
to-->

<asp:dropdownlist onselectedindexchanged="Change_Cust_TB"
id=DropDownList1 runat="server"
DataSource="<%#bizObj.Get_IB_Accounts(IB_Acct)%>" DataTextField="Account"
DataValueField="Account" Width="100px" autopostback="True">
</asp:dropdownlist>

</EditItemTemplate>

</asp:TemplateColumn>

<asp:BoundColumn DataField="Value" ReadOnly="True"
HeaderText="Value"></asp:BoundColumn>

<asp:BoundColumn DataField="Unit" ReadOnly="True"
HeaderText="Units"></asp:BoundColumn>

<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
HeaderText="Edit Acct" CancelText="Cancel" EditText="Edit">
<headerstyle wrap="False"></HeaderStyle>

<itemstyle wrap="False"></ItemStyle>

</asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" HeaderText="Delete Acct"
CommandName="Delete">

<headerstyle wrap="False"></HeaderStyle>

<itemstyle wrap="False"></ItemStyle>

</asp:ButtonColumn>

</Columns>

</asp:datagrid>

When the Delete button is clicked, the onitemcommand event fires and
DGR_List_Command is called:

public void DGR_List_Command(Object sender, DataGridCommandEventArgs e)

{

switch(((LinkButton)e.CommandSource).CommandName)

{

case "Delete":

Delete_Acct(e);

break;

default:

//do nothing

break;

}

}

And the function calls Delete_Acct(e):

public void Delete_Acct(DataGridCommandEventArgs 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_Acct(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.ItemType == ListItemType.EditItem)

{

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

Mar 9 '06 #2
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 ***
Mar 10 '06 #3

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

Similar topics

3
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...
2
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:...
2
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"...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.