使用单个按钮操作多个网格视图?

时间:2015-01-07 16:21:46

标签: c# asp.net ajax gridview tabpanel

好吧我正在使用带有4个选项卡的AJAX选项卡面板,每个选项卡都有GridView绑定到不同的表。我有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>
&#13;
&#13;
&#13;

我没有把CSS代码放在这里,因为它不需要。并且还没有C#代码,因为我需要了解如何使用1个按钮来操作所有4个网格视图。

我希望它像:

If (selectedTab = 1) {
    //DB code for respective table
}

else if (selectedTab= 2) {
    //DB code for respective table
}

依旧......

任何想法或帮助将不胜感激! 谢谢!

1 个答案:

答案 0 :(得分:0)

你在做什么会奏效。如果你创建一个add函数和一个编辑函数,它将GridView作为参数。类似的东西:

protected void Edit(GridView grid)
protected void Add(GridView grid)

然后在按钮单击的功能中执行以下操作:

If (selectedTab = 1) {
       Edit(GridView1);  
}

else if (selectedTab= 2) {
       Edit(GridView2);
}