如何在两个不同的aspx页面中访问相同的网格视图

时间:2015-04-16 04:22:45

标签: asp.net

我有两个页面管理员和教师。我想将网格视图及其管理页面的值调用到教师页面。如何做到这一点

    <asp:GridView ID="Gv1" runat="server" AutoGenerateColumns="False" OnRowDataBound="Gv1_RowDataBound">
        <Columns>
            <asp:BoundField DataField="datedif" HeaderText="Day/Hour" SortExpression="datedif" />
            <asp:TemplateField HeaderText="Hour1">
                <EditItemTemplate>
                    <asp:CheckBox ID="CheckBox1" runat="server" />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox1" runat="server" Enabled='<%# Eval("hour1").ToString().Equals("False") %>' OnCheckedChanged="CheckBox1_CheckedChanged" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Hour2">
                <EditItemTemplate>
                    <asp:CheckBox ID="CheckBox2" runat="server" />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox2" runat="server" Enabled='<%# Eval("hour2").ToString().Equals("False") %>' OnCheckedChanged="CheckBox6_CheckedChanged" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Hour3">
                <EditItemTemplate>
                    <asp:CheckBox ID="CheckBox3" runat="server" />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox3" runat="server" Enabled='<%# Eval("hour3").ToString().Equals("False") %>' OnCheckedChanged="CheckBox3_CheckedChanged" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Hour4">
                <EditItemTemplate>
                    <asp:CheckBox ID="CheckBox4" runat="server" />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox4" runat="server" Enabled='<%# Eval("hour4").ToString().Equals("False") %>' OnCheckedChanged="CheckBox4_CheckedChanged" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Hour5">
                <EditItemTemplate>
                    <asp:CheckBox ID="CheckBox5" runat="server" />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox5" runat="server" Enabled='<%# Eval("hour5").ToString().Equals("False") %>' OnCheckedChanged="CheckBox5_CheckedChanged" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>




          using (SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            foreach (GridViewRow r in Gv1.Rows)
            {
                if (
                    (
                    (
                    (
                       (((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("CheckBox1"))).Checked == true)
                    || (((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("CheckBox2"))).Checked == true)
                    || (((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("CheckBox3"))).Checked == true)
                    || (((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("CheckBox4"))).Checked == true)
                    || (((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("CheckBox5"))).Checked == true)
                    )
                    )
                    )
                    )
                {

                    bool hour1 = (r.FindControl("CheckBox1") as CheckBox).Checked;
                    bool hour2 = (r.FindControl("CheckBox2") as CheckBox).Checked;
                    bool hour3 = (r.FindControl("CheckBox3") as CheckBox).Checked;
                    bool hour4 = (r.FindControl("CheckBox4") as CheckBox).Checked;
                    bool hour5 = (r.FindControl("CheckBox5") as CheckBox).Checked;
                    string datedif = r.Cells[0].Text;
                    string subject1 = ddlsubjects.SelectedValue;
                    string subject2 = ddlsubjects.SelectedValue;
                    string subject3 = ddlsubjects.SelectedValue;
                    string subject4 = ddlsubjects.SelectedValue;
                    string subject5 = ddlsubjects.SelectedValue;
                    con2.Open();
                    SqlCommand comm = new SqlCommand("insert into hourcheck (datedif,hour1,subject1,hour2,subject2,hour3,subject3,hour4,subject4,hour5,subject5) values (@datedif,@hour1,@subject1,@hour2,@subject2,@hour3,@subject3,@hour4,@subject4,@hour5,@subject5) ", con2);
                    comm.Parameters.AddWithValue("@hour1", hour1);
                    comm.Parameters.AddWithValue("@subject1", subject1);
                    comm.Parameters.AddWithValue("@hour2", hour2);
                    comm.Parameters.AddWithValue("@subject2", subject2);
                    comm.Parameters.AddWithValue("@hour3", hour3);
                    comm.Parameters.AddWithValue("@subject3", subject3);
                    comm.Parameters.AddWithValue("@hour4", hour4);
                    comm.Parameters.AddWithValue("@subject4", subject4);
                    comm.Parameters.AddWithValue("@hour5", hour5);
                    comm.Parameters.AddWithValue("@subject5", subject5);
                    comm.Parameters.AddWithValue("@datedif", datedif);
                    comm.ExecuteNonQuery();
                    con2.Close();
                }
            }
        }
    }

这是插入值的方式。我希望在教师页面插入相同的值是可能的

1 个答案:

答案 0 :(得分:0)

我可以通过将UserControl用于网格视图来建议您的问题。这里是参考链接 http://www.aspsnippets.com/Articles/Bind-UserControl-inside-GridView-control-in-ASPNet.aspx