Referincing datagrid with hidden and template column

H

hansiman

I have a real hard time figuring out how to handle/reference
submissions in the datagrid OnUpdateCommand. I've been through quite a
few tutorials....

The datagrid columns

<Columns>
<asp:BoundColumn Visible="False" DataField="EmployeeID"
HeaderText="EmployeeID"></asp:BoundColumn>

<asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="update" CancelText="cancel' EditText="edit">
</asp:EditCommandColumn>

<asp:TemplateColumn SortExpression="Employee"
HeaderText="Employee">
<ItemTemplate>
<asp:Label runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.Employee") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"
ID="Employee"
Text='<%# DataBinder.Eval(Container, "DataItem.Employee") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn SortExpression="EmployeeGroup"
HeaderText="Employee Group;">
<ItemTemplate>
<asp:Label runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.EmployeeGroup") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList Runat="server" ID="cboEmployeeGroup"
DataSource="<%# GetEmployeeGroup() %>"
DataTextField="EmployeeGroup" DataValueField="EmployeeGroup">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>

In another datagrid (with no template columns) I can successfulley
handle submissions this way:
Dim iEmployeeID As Integer = dg.DataKeys(e.Item.ItemIndex)
Dim TextBoxName As TextBox = e.Item.Cells(2).Controls(0)
Dim TextBoxEmail As TextBox = e.Item.Cells(3).Controls(0)

Dim sName As String = TextBoxName.Text
Dim sEmail As String = TextBoxEmail.Text

But it doesn't work this time around.

Please point me in the right direction

/Morten
 
H

hansiman

OK. Now I got around to getting values out of the datagrid in the
OnUpdateCommand rutine:

Datagrid:

<asp:BoundColumn Visible="False" DataField="EmployeeID"
HeaderText="EmployeeID" />

<asp: TemplateColumn
SortExpression="Employee"
HeaderText="Employee">
<ItemTemplate>
<asp:Label
ID="lblEmployee"
runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.Employee") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox
runat="server"
id="txtEmployee"
Text='<%# DataBinder.Eval(Container, "DataItem.Employee") %>' />
</EditItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn
SortExpression="EmployeeGroup"
HeaderText="EmployeeGroup">
<ItemTemplate>
<asp:Label runat="server"
Text='<%# DataBinder.Eval(Container, _
"DataItem.EmployeeGroup") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList Runat="server" ID="cboEmployeeGroup"
DataSource="<%# GetEmployeeGroup() %>"
DataTextField="EmployeeGroup"
DataValueField="EmployeeGroup" />
</EditItemTemplate>
</asp:TemplateColumn>

I get the values using:

Dim iEmployeeID As String = _
CType(e.Item.Cells(0).Controls(0), TextBox).Text

Dim sEmployee As String = _
CType(e.Item.FindControl("txtEmployee"), TextBox).Text

Dim sEmployeeGroup As String = _
CType(e.Item.FindControl("cboEmployeeGroup"), _
DropDownList).SelectedValue

New problem: I get the original values from the TextBox or
DropDownList controls and not the new values entered in the TextBox or
selected in the DropDownList (displayed inthe EditItemTemplate part in
edit mode...!!!)

I'm really confused.
It still seems to be the referencing of the template column that I
can't get right.

I've tried:
For Each dgi As DataGridItem In dg.Items
If dgi.ItemType = ListItemType.EditItem Then
....
but it doesn't work

/Morten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top