Adding Record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a ASP.NET 1.1 DataGrid whose DataSource is set programtically to a
Stored Procedure in SQL Server 2000.

I could see there does not seem to be any build in mechanism to handle
record addition?

How could that be best/easiest achieved?
 
A little confused by the example:
1) Is the example missing the following, or are the doEdit, doCancel method
just for the record creation?
OnUpdateCommand="doEdit" OnCancelCommand="doCancel"

2) I have
<asp:datagrid id="UsersDataGrid" runat="server" DataKeyField="objId"
OnSortCommand="SortUser_OnClick"
AllowSorting="true" AutoGenerateColumns="False" ShowHeader="true"
OnItemCommand="doInsert" ShowFooter="True"
OnUpdateCommand="UsersDataGrid_Update"
OnCancelCommand="UsersDataGrid_Cancel" OnEditCommand="UsersDataGrid_Edit">
<asp:TemplateColumn SortExpression="ExampleCol" HeaderText="example">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "ExampleCol") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="ExampleCol" Columns="5" Text='<%#
DataBinder.Eval(Container.DataItem, "ExampleCol") %>' Runat="server" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="addExampleCol" Columns="5" Runat="Server" />
</FooterTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel"
UpdateText="Update" />
<asp:TemplateColumn>
<FooterTemplate>
<asp:Button CommandName="doInsert" Text="Add" ID="btnAdd"
Runat="server" />
</FooterTemplate>
</asp:TemplateColumn>

protected void doInsert(Object sender, DataGridCommandEventArgs e)
{
((TextBox) e.Item.FindControl("addExampleCol")).Text= "Hello!";
}

I have put a breakpoint within doInsert, but the code does not reach the
breakpoint!!

3) Also, is it possible to have Edit link on each row, but the Add
link/button at footer? If so, how? I try moving EditCommandColumn into the
ItemTemplate of the add record column, but it doesn't work.
 
On closer look, it looks item that OnItemCommand is only trapping standard
columns like
<asp:ButtonColumn Text="Select"
CommandName="SelectItem"></asp:ButtonColumn>

but not
<asp:button/> within a <asp:TemplateColumn/>

How could I sort this out?
 
Solved one problem, my DataGrid rebinding was getting rid of the
OnItemCommand event!

However, How could I mix and match Edit link on each row except the bottom
footer?
 
Patrick - forgive me on this but I'm not following you. What do you mean
by mix and match? Do you mean so that Edit would appear on row 1 , not on
row 2, then on row 3, not on row 4 etc?
 
I mean something like
col1,row1 col2,row1 edit
col1,row2 col2,row2 edit
col1,row3 col2,row3 edit
[txtBox1] [txtBox2] [Add]
 
Hi Patrick,

I saw your another thread on this issue in this newsgroup. Did you get the
answer on that thread?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top