Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何将网格视图值中的选定行id传递给重定向url_Asp.net - Fatal编程技术网

Asp.net 如何将网格视图值中的选定行id传递给重定向url

Asp.net 如何将网格视图值中的选定行id传递给重定向url,asp.net,Asp.net,我有一个gridview来显示表中的请求信息。 我已经添加了一个按钮模板feild,单击该模板后,应该会将用户带到相应的请求url 如何捕获所选requestid并将其作为重定向url中的变量传递 我的gridview <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="roc_id" DataSourceID="analystd

我有一个gridview来显示表中的请求信息。 我已经添加了一个按钮模板feild,单击该模板后,应该会将用户带到相应的请求url

如何捕获所选requestid并将其作为重定向url中的变量传递

我的gridview

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    CellPadding="4" DataKeyNames="roc_id" DataSourceID="analystdefaultview" 
    ForeColor="#333333" GridLines="None" AllowPaging="True"  
    AllowSorting="True" Visible="False" 
        onselectedindexchanged="GridView1_SelectedIndexChanged"> 
    <AlternatingRowStyle BackColor="White" />
    <Columns>

               <asp:CommandField ShowDeleteButton = "true"  />
        <asp:TemplateField HeaderText="RequestId" SortExpression="roc_id">
            <EditItemTemplate>
                <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Bind("roc_id") %>'></asp:HyperLink>
            </EditItemTemplate>
            <ItemTemplate>
               <asp:Button ID = "button2" runat = "server" Text='<%# Bind("roc_id") %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="fundtype" HeaderText="fundtype" 
            SortExpression="fundtype" />
        <asp:BoundField DataField="productionmth" HeaderText="productionmth" 
            SortExpression="productionmth" />
        <asp:BoundField DataField="targetdt" HeaderText="targetdt" 
            SortExpression="targetdt" ReadOnly="True" />
        <asp:BoundField DataField="actualdt" HeaderText="actualdt" 
            SortExpression="actualdt" ReadOnly="True" />
        <asp:BoundField DataField="freqcd" HeaderText="freqcd" 
            SortExpression="freqcd" />
        <asp:BoundField DataField="entereddt" HeaderText="entereddt" 
            SortExpression="entereddt" ReadOnly="True" />
        <asp:BoundField DataField="groupcnt" HeaderText="groupcnt" 
            SortExpression="groupcnt" />
        <asp:BoundField DataField="rptrsrcetxt" HeaderText="rptrsrcetxt" 
            SortExpression="rptrsrcetxt" />
        <asp:BoundField DataField="dateavailable" HeaderText="dateavailable" 
            SortExpression="dateavailable" ReadOnly="True" />
        <asp:BoundField DataField="groupname" HeaderText="groupname" 
            SortExpression="groupname" />
        <asp:BoundField DataField="groupnbr" HeaderText="groupnbr" 
            SortExpression="groupnbr" />
        <asp:BoundField DataField="datarecpdet" HeaderText="datarecpdet" 
            SortExpression="datarecpdet" />
    </Columns>
    <EditRowStyle BackColor="#2461BF" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#EFF3FB" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#F5F7FB" />
    <SortedAscendingHeaderStyle BackColor="#6D95E1" />
    <SortedDescendingCellStyle BackColor="#E9EBEF" />
    <SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>






<asp:SqlDataSource ID="analystdefaultview" runat="server" 
    ConnectionString="<%$ ConnectionStrings:Underwriting %>" 
    SelectCommand="SELECT
       [roc_id]
       ,[fundtype]
       ,Convert(varchar(20),[prodmth],111) as productionmth
       ,Convert(varchar(20),[targetdt],111) as targetdt
       ,Convert(varchar(20),[actualdt],111) as actualdt
       ,[freqcd]
       ,Convert(varchar(20),[entereddt],111) as entereddt
       ,[groupcnt]
       ,[rptrsrcetxt]     
       ,Convert(varchar(20),[date_available],111) as dateavailable
       ,[groupname]
       ,[groupnbr]
       ,[datarecpdet]


        from renoffcyc where opa_id = @opaid and YEAR(prodmth) = YEAR(getdate()) AND MONTH(prodmth) = MONTH(getdate())"

     DeleteCommand = "DElete from renoffcyc where  roc_id = @roc_id" >


    <SelectParameters>
        <asp:ControlParameter ControlID="chooseanalyst" DefaultValue="1" Name="opaid" 
            PropertyName="SelectedValue" />
    </SelectParameters>

</asp:SqlDataSource>

</div>
您需要事件,以及,以便在rowcommand事件中传递值

Html

<ItemTemplate>
           <asp:Button ID = "button2" runat = "server" CommandName="cmdYourButtonPurpose" CommandArgument='<%# Bind("roc_id") %>'
                Text='<%# Bind("roc_id") %>' />
</ItemTemplate>
试试这个

protected void CustomersGridView_SelectedIndexChanged(Object sender, EventArgs e)
{    
     GridViewRow row = GridView1.SelectedRow;   
     string roc_id = GridView1.DataKeys[row.RowIndex].ToString();

     string url = String.Format("http://xxx.yahoo.com/testing/adhoc/Edit.asp?ROCID={0}", roc_id);
     Response.Redirect(url);   
}

在我像以前一样单击按钮进行更改后,它什么也不做。只有属性才支持双向绑定。”CommandArguments不是Button的有效属性。我认为错误是由于在asp:Button中键入错误造成的。我键入的是CommandArguments,而不是CommandArguments。现在更正,尝试一下。As asp:Button support CommandArgument获取此错误编译器错误消息:CS0029:无法将类型“System.Web.UI.WebControl.DataKey”隐式转换为“string”源错误:第67行:GridViewRow行=GridView1.SelectedRow;第68行:第69行:字符串roc_id=GridView1.DataKeys[row.RowIndex];第70行:第71行:Response.Redirect(“+roc_id”);Iam使用下面的,它不会重定向受保护的无效GridView1\u SelectedIndexChanged(对象发送方,EventArgs e){GridViewRow=GridView1.SelectedRow;string roc\u id=GridView1.DataKeys[row.RowIndex].ToString();string url=string.Format(“{0}”,roc\u id);Response.redirect(url);}我仍然在寻求帮助,因为我无法解决这个isuue
void ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
     if(e.CommandName=="cmdYourButtonPurpose")
     {   
         Response.Redirect("http://xxx.yahoo.com/testing/adhoc/Edit.asp?ROCID=" + e.CommandArgument.ToString(););
     }
}
protected void CustomersGridView_SelectedIndexChanged(Object sender, EventArgs e)
{    
     GridViewRow row = GridView1.SelectedRow;   
     string roc_id = GridView1.DataKeys[row.RowIndex].ToString();

     string url = String.Format("http://xxx.yahoo.com/testing/adhoc/Edit.asp?ROCID={0}", roc_id);
     Response.Redirect(url);   
}