- <asp:GridView ID="GridView1" runat="server" Height="174px" Width="355px"
- onrowcommand="GridView1_RowCommand"
- onrowdatabound="GridView1_RowDataBound">
- <Columns>
- <asp:TemplateField ShowHeader="False">
- <ItemTemplate>
- <asp:Button ID="Button1" runat="server" CausesValidation="false"
- CommandName="view" CommandArgument='<%# Eval("ID")%>' onclick="Button1_Click1" Text="点击" />
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- </asp:GridView>
- <asp:Panel ID="Panel1" Visible="false" runat="server" Height="76px" Visible="False">
- <asp:Label ID="Label2" runat="server"></asp:Label>
- </asp:Panel>
后台代码
- protected void Page_Load(object sender, EventArgs e)
- {
- this.Label1.Text = "aaaaaaa";
- if (!Page.IsPostBack)
- {
- getListBox();
- }
- }
- public void getListBox()
- {
- DataTable dt = new DataTable();
- DataColumn dc = new DataColumn();
- dc.ColumnName = "ID";
- dt.Columns.Add(dc);
- DataColumn dc2 = new DataColumn();
- dc2.ColumnName = "Name";
- dt.Columns.Add(dc2);
- DataRow dr;
- for (int i = 0; i <= 5; i++)
- {
- dr = dt.NewRow();
- dr["ID"] = i + 1;
- dr["Name"] = "Name" + i;
- dt.Rows.Add(dr);
- }
- this.GridView1.DataSource = dt;
- this.GridView1.DataKeyNames = new string[] {"ID"};
- this.GridView1.DataBind();
- }
- protected void Button1_Click1(object sender, EventArgs e)
- {
- string Tempstr = ((Button)sender).CommandArgument.ToString();
- //Response.Write("<script>alert('"+Tempstr+"');</script>");
- //这里我让Panel显示出来,并把相应的ID给label。知道了ID你就可惟做很多事了
- this.Panel1.Visible = true;
- this.Label2.Text = Tempstr;
- }