GridView EmptyDataTemplate Question

L

Lee Moore

I am trying to figure out how to handle it when I have an empty dataset
bound to a gridview. I can use the footer when there is data bound to it,
but I cannot figure out how to access controls that I define within the
emptydatatemplate tag. I have tried to access the controls at the form level
with something like this...

Dim TB as TextBox

TB = Form1.FindControl("MyTextBox")

Then using TB.Value elsewhere, but no dice. Any help would be appreciated.
 
L

Lee Moore

I realized my first message made no sense. I want to draw some controls to
enter a new record in the <EmptyDataTemplate> section, since the footer is
not drawn when you bind an empty dataset to a GridView. I cannot figure out
how to access those controls to insert a record. I cannot seem to find the
right parent object to use the FindControl method to assign the control's
value to a variable.

Any help would be great.


<emptydatatemplate>

<table cellspacing="0" cellpadding="2" border="1"
style="color:Black;background-color:LightGoldenrodYellow;border-color:Tan;border-width:1px;border-style:solid;border-collapse:collapse;">
<tr style="color:White;background-color:#707070;">
<th scope="col">Add Goal </th></th>
</tr><tr>
<td>
<asp:TextBox ID="GOAL_TEXT_CONTROL3"
Runat="server"></asp:Textbox>
<input id="CYCLE_ID_CONTROL3" type=hidden
Value='<%#session("CYCLE_ID")%>' runat="server">
<input id="DEPT_ID_CONTROL3" type=hidden
Value='<%#session("DEPT_ID")%>' runat="server">
<asp:Button ID="Button2" Runat="server" Text="Add"
OnClick="InsertRec" />
</td>
</tr>
</table>
</emptydatatemplate>



Here is the Button Event Handler

Sub InsertRec(sender As Object, e As System.EventArgs)
Dim CYCLE_ID as HtmlInputHidden
Dim DEPT_ID as HtmlInputHidden
Dim GOAL_TEXT as TextBox

CYCLE_ID = Form1.FindControl("CYCLE_ID_CONTROL3")
DEPT_ID = Form1.FindControl("DEPT_ID_CONTROL3")
GOAL_TEXT = Form1.FindControl("GOAL_TEXT_CONTROL3")

SqlDataSource1.InsertParameters("CYCLE_ID").DefaultValue =
CInt(CYCLE_ID.Text)
SqlDataSource1.InsertParameters("DEPT_ID").DefaultValue =
CInt(DEPT_ID.Value)
SqlDataSource1.InsertParameters("GOAL_TEXT").DefaultValue =
CStr(GOAL_TEXT.Text)

SqlDataSource1.Insert()

End Sub
 
H

Harolds

Let me get this straight, you have a datagrid with templated columns where
you have placed controls in the footer section, and selected to show footer,
the footer of the datagrid does not display when bound to an empty dataset?
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top