日期:2014-05-17  浏览次数:20493 次

GridView中添加ButtonField后,如何与本行数据结合起来
HTML code

 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AutoGenerateColumns="False" CellPadding="4" GridLines="None" 
            ForeColor="#333333" >
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="#DCDCDC" />
            <PagerSettings Visible="False" />
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <Columns>             
                <asp:TemplateField HeaderText="ID">
                <ItemTemplate>
                <%# Eval("id")%>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="地名">
                <ItemTemplate>
                <%# Eval("the")%>
                </ItemTemplate>
                </asp:TemplateField>  
                <asp:ButtonField HeaderText="标注" Text="标注" ButtonType="Button" />
            </Columns>
        </asp:GridView>




GridView中添加ButtonField后,如何与本行数据结合起来
比如我想在地图上标注绑定的数据,点击标注的时候怎么把列表数据取出来呢?

------解决方案--------------------
HTML code
 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AutoGenerateColumns="False" CellPadding="4" GridLines="None" 
            ForeColor="#333333" onrowcommand="GridView1_RowCommand">
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="#DCDCDC" />
            <PagerSettings Visible="False" />
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <Columns>             
                <asp:TemplateField HeaderText="ID">
                <ItemTemplate>
                <%# Eval("id")%>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="地名">
                <ItemTemplate>
                <%# Eval("the")%>
                </ItemTemplate>
                </asp:TemplateField>  
               <asp:ButtonField HeaderText="标注" Text="标注" ButtonType="Button"  CommandName="biaozhu" CommandArgument='<%#Eval("id")%>'/>
            </Columns>
        </asp:GridView>