无需重定向将查询字符串值传递给当前页面

时间:2015-08-18 05:54:33

标签: c# asp.net query-string

我想传递查询字符串值而不重定向到当前页面我已经尝试过这些代码但我甚至可以看到查询字符串值变量传递到这些页面。我已经附上了我的代码。帮助我解决这些问题              提前致谢

Aspx设计代码

 <div class="col span_1_of_1">
                    <asp:GridView ID="gridweeks" runat="server" CssClass="grid" ShowHeaderWhenEmpty="True" ShowFooter="true" Style="width: 40%" AllowPaging="true" PageIndex="0" PageSize="5" AutoGenerateColumns="False" OnPageIndexChanging="gridweeks_PageIndexChanging">
                        <AlternatingRowStyle BackColor="#dddddd" ForeColor="#284775" />
                        <Columns>
                            <asp:BoundField DataField="weekmonth" HeaderText="Available Month" SortExpression="weekmonth" />
                            <asp:BoundField DataField="dayweek" HeaderText="Available Weeks" SortExpression="dayweek" />
                            <asp:TemplateField HeaderText="Edit / Delete">
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkeditweek" runat="server" Style="color: black" CommandName="assign1" CommandArgument='<%#Eval("dayweek")+","+Eval("weekmonth")%>' OnClick="lnkeditweek_Click1"><i class="fa fa-pencil-square-o" style="color:#2389C9"></i></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <EditRowStyle BackColor="#ffffff" />
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#32404E" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#32404E" ForeColor="White" HorizontalAlign="right" />
                        <RowStyle BackColor="#ffffff" BorderColor="#fff" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" />
                        <SortedAscendingCellStyle BackColor="#E9E7E2" />
                        <SortedAscendingHeaderStyle BackColor="#506C8C" />
                        <SortedDescendingCellStyle BackColor="#FFFDF8" />
                        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                    </asp:GridView>
                    <asp:SqlDataSource ID="batch" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT [dayweek], [weekmonth] FROM [tblslots]"></asp:SqlDataSource>
                </div>

C#代码

LinkButton btn = (LinkButton)(sender);
        lbltxt.Visible = true;
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        con.Open();
        try
        {
            if (btn.CommandName == "assign1")
            {
                string[] commandArgs = btn.CommandArgument.ToString().Split(new char[] { ',' });
                zeroval = commandArgs[0];
                firstval = commandArgs[1];


                for (int j = 0; j < gridweeks.Rows.Count; j++)
                {
                    GridViewRow gw = gridweeks.Rows[j];
                    //string months = gw.Cells[0].Text;
                    // string weeks = gw.Cells[1].Text;
                    for (int i = 0; i < gridsem.Rows.Count; i++)
                    {
                        GridViewRow gs = gridsem.Rows[i];
                        string semester = gs.Cells[0].Text;
                        lbltxt.Text = "You are going to edit for Section : " + Request.QueryString["section"] + ", Week : " + zeroval + " , Session : " + Request.QueryString["session"] + " , Semester : " + semester + " , Month : " + firstval + "";
                        mp5edit.Show();
                    }
                }
                string longurl = "viewavailableweeks.aspx?&ins=" + Request.QueryString["ins"] + "&section=" + Request.QueryString["section"] + "&session=" + Request.QueryString["session"] + "&academicyear=" + Request.QueryString["academicyear"] + "&month='" + firstval + "'+&week='" + firstval + "'";
                var uriBuilder = new UriBuilder(longurl);
                var query = HttpUtility.ParseQueryString(uriBuilder.Query);
                longurl = uriBuilder.ToString();
            }
        }

0 个答案:

没有答案