you can access through the e.Item property, for example void ItemsGrid_Command(Object sender, DataGridCommandEventArgs e) { TextBox tb = e.Item.FindControl("YourTextBoxID") as TextBox; if (tb != null) { Page.Response.Write(tb.Text); } }
int a=int.Parse(((TextBox)e.Item.FindControl("txtPage")).Text); int c=int.Parse(((Label)e.Item.FindControl("lbCountPage1")).Text); 如果是字符串的话,就不用int.Parse()转换了
how does your template look like??<asp:LinkButton CommandName='commcontent' runat="server" id="LinkButton2" Text='<%# ... %>' />
To Saucer: No... Just like this: <asp:LinkButton CommandName='commcontent' runat="server" id="LinkButton2"> <%#...%></LinkButton> Is that right?
no, then <%#...%> became a child control of LinkButton,and of DataBoundLiteralControl type, use my method<asp:LinkButton CommandName='commcontent' runat="server" id="LinkButton2" Text='<%# ... %>' /> or you have to doDataBoundLiteralControl dlc = LinkButton2.Controls[0] as DataBoundLiteralControl; Response.Write(dlc.Text);
Ok,I got it. thank Saucer very much.In fact,I have already solved this problem,but with another method.Because I thought that method is not good enough,then I resorted to CSDN for a better way.
void ItemsGrid_Command(Object sender, DataGridCommandEventArgs e)
{
TextBox tb = e.Item.FindControl("YourTextBoxID") as TextBox;
if (tb != null)
{
Page.Response.Write(tb.Text);
}
}
int c=int.Parse(((Label)e.Item.FindControl("lbCountPage1")).Text);
如果是字符串的话,就不用int.Parse()转换了
{ if (e.CommandName=="commcontent")
{
LinkButton lb=e.Item.FindControl("LinkButton2") as LinkButton;
//取得模板列中的LINKBUTTON SqlCommand comm=new SqlCommand();
comm.Connection=this.sqlConn_Notice;
comm.CommandText="Display_Notice";
comm.CommandType=CommandType.StoredProcedure;
comm.Parameters.Add("@NotTitle",SqlDbType.VarChar,100,"NotTile");
comm.Parameters.Add("@NotContent",SqlDbType.VarChar,4000,"NotContent");
comm.Parameters["@NotTitle"].Value=lb.Text;
//将LINKBUTTON的TEXT属性值传给参数 comm.Parameters["@NotContent"].Direction=ParameterDirection.Output; this.sqlConn_Notice.Open();
int i=comm.ExecuteNonQuery();
ElectSite.NotContent.content=comm.Parameters["@NotContent"].Value.ToString();
this.sqlConn_Notice.Close(); Response.Redirect("NotContent.aspx",true);
}
}
按照思归的说法应该是这样做了吧,但是这样还是不能取出LINKBUTTON的TEXT属性值啊?
No...
Just like this:
<asp:LinkButton CommandName='commcontent' runat="server" id="LinkButton2">
<%#...%></LinkButton>
Is that right?
or you have to doDataBoundLiteralControl dlc = LinkButton2.Controls[0] as DataBoundLiteralControl;
Response.Write(dlc.Text);
thank Saucer very much.In fact,I have already solved this problem,but with another method.Because I thought that method is not good enough,then I resorted to CSDN for a better way.