EDITED QUESTION從的ImageButton傳遞參數背後
到代碼我想通過一個變量,在這種情況下「名稱」包含字符串話費,後面方法的代碼,並使用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;
}
}
我想我需要首先綁定一些東西,但老實說我不知道。我打印時只是空白。有沒有人
編輯
我想要做的是動態創建一個表之前處理這個。名稱變量從數據庫中獲取,然後根據該名稱創建一個表。我希望表格的最後一列是X,所以我可以刪除該行中的所有內容。我正在使用一個imagebutton。這裏是我的代碼
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>");
}
Try,DeleteButton.CommandArgument = name;在Page_Load中。 – adatapost