gridview 中使用linkbutton 实现多值传递

选课系统中,同时选中 书号,和教师的ID 号:

 

a.aspx 中

 

<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label

 <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>

<asp:GridView ID="GridView1" runat="server" 
                DataKeyNames="cid" CellPadding="4" ForeColor="#333333" GridLines="None"
              
                Width="449px"  >
                <RowStyle BackColor="#EFF3FB" />
                <Columns>
                    <asp:BoundField DataField="cid" HeaderText="课程号" ReadOnly="True"
                        SortExpression="cid" />
                    <asp:BoundField DataField="cname" HeaderText="课程名" SortExpression="cname" />
                    <asp:BoundField DataField="credit" HeaderText="学分"
                        SortExpression="credit" />
                    <asp:BoundField DataField="hour" HeaderText="课时" SortExpression="hour" />
                    <asp:BoundField DataField="tid" HeaderText="教师名" SortExpression="" />
                    <asp:TemplateField><ItemTemplate>  
                   
 
                    <asp:LinkButton ID="LinkButton1" runat="server" OnCommand="click" CommandArgument='<%#eval_r("cid")+","+eval_r("tid")%>'>
                        选课</asp:LinkButton>
                   </ItemTemplate></asp:TemplateField>
                </Columns>
           
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#2461BF" />
                <AlternatingRowStyle BackColor="White" />
           
            </asp:GridView>
          

a.aspx.cs 中收取参数的过程:

protected void click(object sender, CommandEventArgs e)
    {
     //  int id = int.Parse((string)e.CommandArgument);
   //    string cid = id.ToString().Trim();

       string[] str = e.CommandArgument.ToString().Split(',');

    //   model.id = Convert.ToInt32(str[1]);

       

      //  this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert(' "+cid+"')</script>");

       Label2.Text = str[0];
       Label3.Text = str[1];
    }

posted @ 2012-08-09 16:33  少雨愁  阅读(288)  评论(0编辑  收藏  举报