- How to bind the data to Repeater using stored procedure with parameters.
- How to get the data by using DeptId.
- How to bind empty Repeater with header.
- How to create custom message when no data present in DataSet in Asp.net.
Create a table like as follows to demonstrate the above concepts.
Copy the following script run in your database to create USP_GetEmployeesByDeptId stored procedure.
- Create procedure [dbo].[USP_GetEmployeesByDeptId]
- @DeptId int
- AS
- Begin
- Select * from Mas_Employee
- where DeptId = @DeptId
- END
Create new ASP.NET Empty Web Application give it to meaning full name.
Add one webfrom to your project.
Web.config
Make the Connection string in web.Config.
- <connectionStrings>
- <add name="conStr" connectionString="Password = 1234; User ID=sa; Database = DB_DEV_JAI; Data Source = ."
- providerName="System.Data.SqlClient" />
- </connectionStrings>
.aspx:
Copy the following code in your design page.
- <div align="center" style="width:30%;">
- <asp:TextBox ID="txtDeptID" runat="server" placeholder="Enter DeptId"></asp:TextBox>
- <asp:Button ID="btnGetData" runat="server" Text="GetData" OnClick="btnGetData_Click" />
- <br />
- <br />
- <asp:Repeater ID="rptEmpDetails" runat="server" OnItemDataBound="rptEmpDetails_ItemDataBound">
- <HeaderTemplate>
- <table border="1" style="width:100%;">
- <tr style="background-color: Blue; color: #FFF;" align="center">
- <th>
- Name
- </th>
- <th>
- Salary
- </th>
- <th>
- DeptId
- </th>
- </tr>
- </HeaderTemplate>
- <ItemTemplate>
- <tr style="background-color: white;" align="center">
- <td><%#Eval("Name") %>
- </td>
- <td><%#Eval("Salary")%>
- </td>
- <td><%#Eval("DeptId")%>
- </td>
- </tr>
- </ItemTemplate>
- <FooterTemplate>
- </table>
- <div id="dvNoRecords" runat="server" visible="false" style="text-align: center; color: Red;">
- <font>
- <b>
- <i>No records to display.</i>
- </b>
- </font>
- </div>
- </FooterTemplate>
- </asp:Repeater>
- </div>

Join the conversation! Your thoughts help the community grow.