[http://www.cnblogs.com/cnaspnet/archive/2007/05/04/669410.html]
也是在这次项目开发遇到的问题,本来放在一起的,后来发现太长了,所有就分开来写.
不过都是一些非常简单的问题,怕忘记,在这里作一个记录.

GridView模版列中Button取值问题:
 1  <asp:GridView ID="GridView1" runat="server" DataKeyNames="id" AutoGenerateColumns="
               False
" ShowHeader="False" Width="100%" OnRowDataBound="
                GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand">
 2             <Columns>
 3                 <asp:BoundField DataField="dept" >
 4                     <ItemStyle Height="20px" Width="10%" HorizontalAlign="Center" />
 5                 </asp:BoundField>
 6                 <asp:BoundField DataField="deptnm" >
 7                     <ItemStyle Width="15%" />
 8                 </asp:BoundField>
 9                 <asp:TemplateField>
10                     <ItemTemplate>
11                         意见:<asp:TextBox CssClass="inputLine" ID="txtNotion" runat="server" Width="300px"></asp:TextBox>
12                     </ItemTemplate>
13                     <ItemStyle Width="40%" />
14                 </asp:TemplateField>
15                 <asp:TemplateField>
16                     <ItemTemplate>
17                         <asp:HiddenField ID="hditem" runat="server" Value='<%# Eval("item") %>' />
18                         <asp:RadioButtonList ID="rblidea" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
19                             <asp:ListItem Value="1">同意</asp:ListItem>
20                             <asp:ListItem Value="0">不同意</asp:ListItem>
21                         </asp:RadioButtonList>
22                     </ItemTemplate>
23                     <ItemStyle HorizontalAlign="Center" Width="20%" />
24                 </asp:TemplateField>
25                 <asp:TemplateField>
26                     <ItemTemplate>
27                         <asp:Button ID="btnSubVise" CommandName="vise" CommandArgument='<%# Eval("id") %>'
                                 runat="server" Text="提 交" CssClass="Sub_button2" />&nbsp;
28                         <input id="ReSubVise" type="reset" value="重 置" class="Sub_button2" runat="server" />
29                     </ItemTemplate>
30                     <ItemStyle HorizontalAlign="Center" Width="15%" />
31                 </asp:TemplateField>
32             </Columns>
33         </asp:GridView>

点击"提交"这个按钮,想取得"意见"这个TextBox的值.

 1 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
 2         {
 3             GridViewRow row = ((Control)e.CommandSource).BindingContainer as GridViewRow;
 4             int index = row.RowIndex;
 5 
 6             string strid = e.CommandArgument.ToString();
 7 
 8             if (e.CommandName == "vise")
 9             {
10                 string strid = GridView1.DataKeys[index].Value.ToString();
11                 TextBox txtNotion = (TextBox)row.FindControl("txtNotion");
12 
13                 Response.Write(txtNotion.Text.ToString());
14             }
15         }

e.CommandArgument是取CommandArgument='<%# Eval("id") %>'的值.index是取GridView中DataKeyNames="id"的值.