Adding Record to Empty Dataset?
So I have this:
Code:
Dim SelectCommand As String = "SELECT CDID, CSTitle,
CSScript from CustomScripts WHERE UserID = " &
Context.Request.QueryString("UserID")
Problem is that if that if there arent any records to bind, and the user clicks to add a new record, an empty row appears.
I am creating the dataset like so:
Code:
<asp:datagrid
id="DataGrid1"
runat="server"
BackColor="#DEBA84"
Font-Size="X-Small"
BorderColor="#DEBA84"
BorderStyle="None"
BorderWidth="1px"
width="100%"
CellSpacing="1"
GridLines="Horizontal"
CellPadding="1"
OnPageIndexChanged="DataGrid_Page"
AllowPaging="True"
OnDeleteCommand="DataGrid_Delete" OnCancelCommand="DataGrid_Cancel" OnUpdateCommand="DataGrid_Update" OnEditCommand="DataGrid_Edit"
OnItemCommand="DataGrid_ItemCommand"
DataKeyField="CDID"
DataMember="Table"
ShowFooter="True"
AutoGenerateColumns="False">
<FooterStyle forecolor="#8C4510" backcolor="#F7DFB5">
</FooterStyle>
<SelectedItemStyle font-bold="True" forecolor="White" backcolor="#738A9C">
</SelectedItemStyle>
<ItemStyle forecolor="#8C4510" backcolor="#FFF7E7">
</ItemStyle>
<HeaderStyle font-bold="True" forecolor="White" backcolor="#A55129">
</HeaderStyle>
<Columns>
<asp:BoundColumn Visible="False" DataField="CDID">
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Script Title (max 15 char)">
<ItemTemplate>
<asp:Label runat="server" text='<%# DataBinder.Eval(Container, "DataItem.CSTitle") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CSTitle") %>' MaxLength="15" Size="7">
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Script Text (max 500 char)">
<ItemTemplate>
<asp:Label runat="server" text='<%# DataBinder.Eval(Container, "DataItem.CSScript") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CSScript") %>' MaxLength="500" size="15" height="55px" TextMode="MultiLine">
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit">
<ItemStyle font-size="Smaller" width="10%">
</ItemStyle>
</asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete">
<ItemStyle font-size="Smaller" width="10%">
</ItemStyle>
</asp:ButtonColumn>
</Columns>
<PagerStyle font-size="Smaller" horizontalalign="Center" forecolor="#8C4510" position="TopAndBottom">
</PagerStyle>
</asp:datagrid>
So I assume it has something to do with the fact that I am using template columns and I need to handle it just a little bit differently, but I am unaware on accomplishing this.
Anyone shed some light on this for me?