Home All Groups Group Topic Archive Search About

GridView EmptyDataTemplate Question

Author
22 Jul 2005 1:24 PM
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.

Author
22 Jul 2005 1:36 PM
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
Author
22 Jul 2005 5:28 PM
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?

Show quoteHide quote
"Lee Moore" wrote:

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