F
Frank
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
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