使用单个按钮操作多个网格视图
本文关键字:网格 视图 操作 单个 按钮 | 更新日期: 2023-09-27 18:36:32
好的,所以我使用的是带有 4 个选项卡的 AJAX 选项卡面板,每个选项卡都有绑定到不同表的 GridViews。我有 1 个添加按钮和 1 个编辑按钮。是否可以创建代码,以便将用户在字段中输入的数据添加到所选选项卡中?可能吗?要么通过 if/else-if 语句还是切换?但我不知道我会把支票放在什么上面?选项卡 ID?这是我的ASPX代码。
<div class="gview">
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="3" Width="614px">
<asp:TabPanel runat="server" HeaderText="Cardiology" ID="TabPanel1">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Designation" HeaderText="Designation" SortExpression="Designation" />
<asp:BoundField DataField="Ward_rounds" HeaderText="Ward_rounds" SortExpression="Ward_rounds" />
<asp:BoundField DataField="Slot1" HeaderText="Slot1" SortExpression="Slot1" />
<asp:BoundField DataField="Slot2" HeaderText="Slot2" SortExpression="Slot2" />
<asp:BoundField DataField="Slot3" HeaderText="Slot3" SortExpression="Slot3" />
<asp:BoundField DataField="Slot4" HeaderText="Slot4" SortExpression="Slot4" />
<asp:BoundField DataField="BreakTime" HeaderText="BreakTime" SortExpression="BreakTime" />
<asp:BoundField DataField="Slot5" HeaderText="Slot5" SortExpression="Slot5" />
<asp:BoundField DataField="Slot6" HeaderText="Slot6" SortExpression="Slot6" />
<asp:BoundField DataField="Slot7" HeaderText="Slot7" SortExpression="Slot7" />
<asp:BoundField DataField="Slot8" HeaderText="Slot8" SortExpression="Slot8" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:masterConnectionString %>" SelectCommand="SELECT * FROM [Cardio_schedule]"></asp:SqlDataSource>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel runat="server" HeaderText="Neurology" ID="TabPanel2">
<ContentTemplate>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Designation" HeaderText="Designation" SortExpression="Designation" />
<asp:BoundField DataField="Ward_Rounds" HeaderText="Ward_Rounds" SortExpression="Ward_Rounds" />
<asp:BoundField DataField="Slot1" HeaderText="Slot1" SortExpression="Slot1" />
<asp:BoundField DataField="Slot2" HeaderText="Slot2" SortExpression="Slot2" />
<asp:BoundField DataField="Slot3" HeaderText="Slot3" SortExpression="Slot3" />
<asp:BoundField DataField="Slot4" HeaderText="Slot4" SortExpression="Slot4" />
<asp:BoundField DataField="BreakTime" HeaderText="BreakTime" SortExpression="BreakTime" />
<asp:BoundField DataField="Slot5" HeaderText="Slot5" SortExpression="Slot5" />
<asp:BoundField DataField="Slot6" HeaderText="Slot6" SortExpression="Slot6" />
<asp:BoundField DataField="Slot7" HeaderText="Slot7" SortExpression="Slot7" />
<asp:BoundField DataField="Slot8" HeaderText="Slot8" SortExpression="Slot8" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:masterConnectionString %>" SelectCommand="SELECT * FROM [Neuro_schedule]"></asp:SqlDataSource>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel runat="server" HeaderText="Dermatology" ID="TabPanel3">
<ContentTemplate>
<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Designation" HeaderText="Designation" SortExpression="Designation" />
<asp:BoundField DataField="Ward_Rounds" HeaderText="Ward_Rounds" SortExpression="Ward_Rounds" />
<asp:BoundField DataField="Slot1" HeaderText="Slot1" SortExpression="Slot1" />
<asp:BoundField DataField="Slot2" HeaderText="Slot2" SortExpression="Slot2" />
<asp:BoundField DataField="Slot3" HeaderText="Slot3" SortExpression="Slot3" />
<asp:BoundField DataField="Slot4" HeaderText="Slot4" SortExpression="Slot4" />
<asp:BoundField DataField="BreakTime" HeaderText="BreakTime" SortExpression="BreakTime" />
<asp:BoundField DataField="Slot5" HeaderText="Slot5" SortExpression="Slot5" />
<asp:BoundField DataField="Slot6" HeaderText="Slot6" SortExpression="Slot6" />
<asp:BoundField DataField="Slot7" HeaderText="Slot7" SortExpression="Slot7" />
<asp:BoundField DataField="Slot8" HeaderText="Slot8" SortExpression="Slot8" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:masterConnectionString %>" SelectCommand="SELECT * FROM [Derma_Schedule]"></asp:SqlDataSource>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel runat="server" HeaderText="Opthalmology" ID="TabPanel4">
<ContentTemplate>
<asp:GridView ID="GridView4" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource4">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Designation" HeaderText="Designation" SortExpression="Designation" />
<asp:BoundField DataField="Ward_Rounds" HeaderText="Ward_Rounds" SortExpression="Ward_Rounds" />
<asp:BoundField DataField="Slot1" HeaderText="Slot1" SortExpression="Slot1" />
<asp:BoundField DataField="Slot2" HeaderText="Slot2" SortExpression="Slot2" />
<asp:BoundField DataField="Slot3" HeaderText="Slot3" SortExpression="Slot3" />
<asp:BoundField DataField="Slot4" HeaderText="Slot4" SortExpression="Slot4" />
<asp:BoundField DataField="BreakTime" HeaderText="BreakTime" SortExpression="BreakTime" />
<asp:BoundField DataField="Slot5" HeaderText="Slot5" SortExpression="Slot5" />
<asp:BoundField DataField="Slot6" HeaderText="Slot6" SortExpression="Slot6" />
<asp:BoundField DataField="Slot7" HeaderText="Slot7" SortExpression="Slot7" />
<asp:BoundField DataField="Slot8" HeaderText="Slot8" SortExpression="Slot8" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:masterConnectionString %>" SelectCommand="SELECT * FROM [Optha_schedule]"></asp:SqlDataSource>
</ContentTemplate>
</asp:TabPanel>
</ajaxToolkit:TabContainer>
</div>
我没有把CSS代码放在这里,因为它不是必需的。而且还没有 C# 代码,因为我需要一些关于如何使用 1 个按钮来操作所有 4 个网格视图的想法。
我希望它像:
If (selectedTab = 1) {
//DB code for respective table
}
else if (selectedTab= 2) {
//DB code for respective table
}
等等..
任何想法或帮助将不胜感激!谢谢!
你正在做的事情会起作用。 如果创建一个添加函数和一个编辑函数,将 GridView 作为参数。 像这样:
protected void Edit(GridView grid)
protected void Add(GridView grid)
然后在按钮单击的函数中,您可以执行以下操作:
If (selectedTab = 1) {
Edit(GridView1);
}
else if (selectedTab= 2) {
Edit(GridView2);
}