Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gridview not displaying .. when no row data is from bound datasource

Status
Not open for further replies.

fr2

Programmer
May 13, 2008
45
US
I have a Gridview bound to a datasource ds1 ...

The Gridview is setup for SELECT INSERT UPDATE DELETE ..

It works fine as long as teh datasource returns at least one row ...

When there is no row .. nothing displays at all ... Well I have an "Add" or "Insert" button available for the user to add a row ... but nothing shows up! ..

When I put a dummy blank record in the database table .. the gridview shows up .. I wanted to use this easy way out .. but my boss does not want all those blank dummy rows in the database table ...

How can I get aroound this zero record scenario. The bound datasource really saves a lot of coding .. but I an stuck with the zero ( no row) scenario ...

Any help with how to get around it?
 
Check the rowcount of ds1. If it is 0, then manually add a row to ds1, then bind to the grid. This way you have a blank row for entering data, and it is not in the db.
 
Thanks ..but I think I'm still stuck! .. I know how to get the rowcount from a dataset (table) and insert a row into a dataset table ....

but how do I get the rowcount for a datasource ... I have SELECT command in there ... I also have the INSERT command in there .. pls give a hint on how to check the rowcount .. and use the insert manually .. pls

Thanks


<asp:SqlDataSource ID="ds1" runat="server" ConnectionString="<%$ ConnectionStrings:myConstring %>" DeleteCommand="DELETE FROM [tblEmploymentHistory] WHERE [EmploymentId] = @EmploymentId" InsertCommand="INSERT INTO [tblEmploymentHistory] ([Employer], [Position], [Hours], [StartDate], [EndDate], [AcademicAppId]) VALUES (@Employer, @Position, @Hours, @StartDate, @EndDate, @AcademicAppId)" SelectCommand="SELECT [EmploymentId], [Employer], [Position], [Hours], [StartDate], [EndDate], [AcademicAppId] FROM [tblEmploymentHistory] WHERE ([AcademicAppId] = @AcademicAppId)" UpdateCommand="UPDATE [tblEmploymentHistory] SET [Employer] = @Employer, [Position] = @Position, [Hours] = @Hours, [StartDate] = @StartDate, [EndDate] = @EndDate WHERE [EmploymentId] = @EmploymentId">
<DeleteParameters>
<asp:parameter Name="EmploymentId" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Employer" Type="String" />
<asp:parameter Name="Position" Type="String" />
<asp:parameter Name="Hours" Type="Decimal" />
<asp:parameter Name="StartDate" Type="DateTime" />
<asp:parameter Name="EndDate" Type="DateTime" />

<asp:parameter Name="EmploymentId" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="txtAppId" Name="AcademicAppId" PropertyName="Text"
Type="Int32" DefaultValue="0" />
</SelectParameters>
<InsertParameters>
<asp:parameter Name="Employer" Type="String" />
<asp:parameter Name="Position" Type="String" />
<asp:parameter Name="Hours" Type="Decimal" />
<asp:parameter Name="StartDate" Type="DateTime" />
<asp:parameter Name="EndDate" Type="DateTime" />
<asp:controlParameter ControlID="txtAppId" Name="AcademicAppId" PropertyName="Text" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
 
I assumed you were using a dataset or datatable. Don't use the datasource controls, you cannot debug them. Write stored procedures for your Select, Delete.. etc. Call them using a sqldataadapter or command object. Or better yet, use something like Microsoft's Data AccessApplication block.
 
is there a link for sample code or project .. (VB)

for Gridview .. Inserts .. datasource ... that I can explore ...

Been seacrhing all over .. keep getting C# .. or kind of incomplete stuff!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top