查询字符串在网格视图中不起作用 [英] Query string not working inside grid view

查看:71
本文介绍了查询字符串在网格视图中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:GridView ID="ResultGridView" runat="server" AutoGenerateColumns="False" ShowFooter="true" 

    DataKeyNames="RegionProjectID"  

    AllowPaging="True"  

    CellPadding="3"  

    OnPageIndexChanging="ResultGridView_PageIndexChanging"  

    OnRowDeleting="ResultGridView_RowDeleting"  

    CssClass="mGrid" 

    OnRowEditing="ResultGridView_RowEditing"  

    OnRowUpdating="ResultGridView_RowUpdating"  

    OnRowCancelingEdit="ResultGridView_RowCancelingEdit"  

    PageSize="15" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellSpacing="2" 

     OnRowCommand="ResultGridView_RowCommand" > 
        <Columns> 
            <asp:BoundField DataField="RegionProjectID" HeaderText="Region ID" InsertVisible="False" 

                ReadOnly="True" SortExpression="RegionProjectID" Visible="false" /> 
            <asp:TemplateField HeaderText="Region Name" SortExpression="RegionProjectName"> 
                <EditItemTemplate> 
                    <asp:TextBox ID="txtRegion" Width="250px" runat="server" Text='<%# Bind("RegionProjectName") %>'></asp:TextBox> 
                </EditItemTemplate> 
                <FooterTemplate> 
                <asp:TextBox ID="txtRegion1" runat="server"  Width="250px"></asp:TextBox>  
                </FooterTemplate> 
                <ItemTemplate> 
                   <asp:LinkButton ID="LinkButton3" CommandName="Details" CommandArgument='<%# Eval("RegionProjectID") %>' Text='<%# Bind("RegionProjectName") %>' runat="server" />  
                </ItemTemplate> 
            </asp:TemplateField> 
 
            <asp:TemplateField HeaderText="Edit" ShowHeader="False">  
            <EditItemTemplate>  
              <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>  
              <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>  
            </EditItemTemplate>  
            <FooterTemplate>  
              <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="AddNew" Text="Add New"></asp:LinkButton>  
            </FooterTemplate>  
            <ItemTemplate>  
              <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>  
            </ItemTemplate>  
            </asp:TemplateField>  
            <asp:CommandField HeaderText="Delete" ShowDeleteButton="True"  ShowHeader="True" />  
           <%-- <asp:CommandField HeaderText="Select" ShowSelectButton="True"  ShowHeader="True"/> --%> 
 
        </Columns> 
        <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" /> 
        <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /> 
        <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" /> 
        <%--<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />--%> 
        <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" /> 
    </asp:GridView>` 


protected void ResultGridView_RowCommand(object sender, GridViewCommandEventArgs e) 
    { 
        if (e.CommandName == "Details") 
        { 
            Server.Transfer("Default3.aspx?ID=" + e.CommandArgument.ToString());  
 
        }  
 
        if (e.CommandName.Equals("AddNew")) 
        { 
 
            TextBox txtRegion1 = (TextBox)ResultGridView.FooterRow.FindControl("txtRegion1"); 
            TextBox txtNatureOFWork1 = (TextBox)ResultGridView.FooterRow.FindControl("txtNatureOFWork1"); 
            if (txtRegion1.Text != "") 
            { 
                cmd.Connection = conn; 
                cmd.CommandText = "INSERT INTO RegionAndProjectInfo(RegionProjectName, NatureOFWorkID ) Values('" + txtRegion1.Text + "', '" + ddlnatureOfWork.SelectedValue.ToString() + "')"; 
                conn.Open(); 
                cmd.ExecuteNonQuery(); 
            } 
            FillVendorGrid(); 
            conn.Close(); 
        } 
    } 


每当用户单击网格上的RegionProjectName字段时,我都试图从查询字符串传递网格的RegionProjectID列.我已经将RegionProjectname设置为超链接,并且在下面也可以找到该代码.但这是行不通的.请提出建议或帮助我,为什么它不起作用.在我的网格视图中也启用了分页.


I am trying to pass RegionProjectID column of my grid from query string when ever a user will click on the RegionProjectName field on the grid. I had made RegionProjectname as hyperlink and below you can find the Code also. But this is not working . Please suggest me or help that why it is not working. The pagin is also enabled in my grid view.

推荐答案


试试这个:
Hi,
Try this:
<asp:templatefield headertext="Region Name" sortexpression="RegionProjectName"> 
    <edititemtemplate> 
        <asp:textbox id="txtRegion" width="250px" runat="server" text="<%# Bind("RegionProjectName") %>"></asp:textbox> 
    </edititemtemplate> 
    <footertemplate> 
    <asp:textbox id="txtRegion1" runat="server" width="250px"></asp:textbox>  
    </footertemplate> 
    <itemtemplate> 
       <asp:hyperlink id="LinkButton3" navigateurl='<%# "Default3.aspx?ID=" + Eval("RegionProjectID")%>' text='<%# Bind("RegionProjectName")%>' runat="server" />  
    </itemtemplate> 
</asp:templatefield> 




一切顺利.




All the best.


您可以使用会话变量.

You can use session variable.

protected void GridView_Documents_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int DocumentId = Convert.ToInt32(e.CommandArgument);
            Session["DocumentId"] = Convert.ToInt32(e.CommandArgument);
            Response.Redirect("~/Document.aspx");
        }




并在document.aspx的页面加载中




and in the pageload of document.aspx

int documentId = Convert.ToInt32(Session["Document"]);


这篇关于查询字符串在网格视图中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆