我想将一个变量(在本例中为包含字符串 bill 的“名称”)传递给方法背后的代码并使用 debug.print 来查看它
string name = "bill";
<asp:ImageButton runat="server" id="DeleteButton" ImageUrl="Images/delete.jpg"
CommandArgument='<%# Eval("name") %>' CommandName="ThisBtnClick" text="Delete Me" onclick="DeleteMonth" />
我试过了:
CommandArgument='<%# Eval("name") %>'
CommandArgument='<%# Bind("name") %>'
CommandArgument='<%= "name" %>
这是我的打印功能
protected void DeleteMonth(object sender, EventArgs e)
{
ImageButton btn = (ImageButton)sender;
switch (btn.CommandName)
{
case "ThisBtnClick":
Debug.Print("--" + btn.CommandArgument.ToString());
break;
case "ThatBtnClick":
break;
}
}
我想我需要先对一些东西进行数据绑定,但老实说我不知道。当我打印时,我只是得到一个空白。有没有人处理过这个
编辑
我想要做的是动态创建一个表。name 变量从数据库中提取,然后基于该名称创建一个表。我希望表格的最后一列是 X,这样我就可以删除该行中的所有内容。我正在使用图像按钮。这是我的代码
using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(sqlConnectionString))
{
conn.Open();
string query = "SELECT * FROM dbo.Archive";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(query, conn);
System.Data.SqlClient.SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
string name, created, 1Updated, 2Updated, 3Updated;
name = rdr.GetString(1); // name of month
if (!(rdr.IsDBNull(2))) // checks date for a null value
{ created = rdr.GetDateTime(2).ToString(); }// if not null date is turned into a string and saved in a variable
else
{ created = "---"; } // else date is given a default value
if (!(rdr.IsDBNull(3)))
{ 1Updated = rdr.GetDateTime(3).ToString(); }
else
{ 1Updated = "---"; }
if (!(rdr.IsDBNull(4)))
{ 2Updated = rdr.GetDateTime(4).ToString(); }
else
{ 2Updated = "---"; }
if (!(rdr.IsDBNull(5)))
{ 3Updated = rdr.GetDateTime(5).ToString(); }
else
{ 3Updated = "---"; }
Response.Write("<tr><td>" + name + "</td>");
Response.Write("<td>" + created + "</td>");
Response.Write("<td>" + 1Updated + "</td>");
Response.Write("<td>" + 2Updated + "</td>");
Response.Write("<td>" + 3Updated + "</td>");
Response.Write("<td><a>1</a></td>");
Response.Write("<td><a>2</a></td>");
Response.Write("<td><a>3</a></td>");
Response.Write("<td><a>Compliance Summary</a></td>");
Response.Write("<td align = 'center'>"+name);%>
<asp:ImageButton runat="server" id="DeleteButton" ImageUrl="Images/delete.jpg"
CommandArgument='<%# Eval("name") %>' CommandName="ThisBtnClick" text="Delete Me" onclick="DeleteMonth" />
<% Response.Write("</td></tr>");
}