Hi GTTravis,
I have cross checked your code and its working fine and i am able to get the CommandArgument.
I have created a sample which full fill your requirement you need to modify the code according to your need.
Refer below article for DataBase Table which i have used to create a sample Customers table i have used from database.
Install Microsoft Northwind and Pubs Sample databases in SQL Server Management Studio
Refer below sample code.
HTML
<div>
<asp:ListView ID="lvCustomers" runat="server" GroupPlaceholderID="groupPlaceHolder1"
ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<th>
CustomerId
</th>
<th>
ContactName
</th>
<th>
Country
</th>
</tr>
<asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<%# Eval("CustomerId") %>
</td>
<td>
<%# Eval("ContactName") %>
</td>
<td>
<%# Eval("Country") %>
</td>
<td>
<asp:ImageButton ID="Imgproc" ToolTip="Click to perform bill run for this area" ImageUrl="~/imgicons/bprocess.jpg"
Height="40px" Width="40px" OnLoad="Imgproc_Load" CommandArgument='<% #Eval("CustomerId") %>'
AlternateText="Process" runat="server" />
<asp:ImageButton ID="Imgrev" ToolTip="Click to reverse bill run for this area" ImageUrl="~/imgicons/reverse1.png"
Height="40px" Width="40px" OnLoad="ImgRev_Load" CommandArgument='<% #Eval("CustomerId") %>'
AlternateText="Run" runat="server" />
</td>
</ItemTemplate>
</asp:ListView>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindListView();
}
}
private void BindListView()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT TOP 10 CustomerId, ContactName, Country FROM Customers";
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
sda.Fill(dt);
lvCustomers.DataSource = dt;
lvCustomers.DataBind();
}
}
}
}
protected void Imgproc_Load(object sender, EventArgs e)
{
ImageButton img = (ImageButton)sender;
string areaid = img.CommandArgument.ToString();
try
{
if (areaid == "AAFKM" || areaid == "BERGS")
{
img.Visible = false;
}
else
{
img.Visible = true;
}
}
catch
{
}
}
protected void ImgRev_Load(object sender, EventArgs e)
{
ImageButton img = (ImageButton)sender;
string areaid = img.CommandArgument.ToString();
try
{
if (areaid == "ALFKI" || areaid == "BERGS")
{
img.Visible = true;
}
else
{
img.Visible = false;
}
}
catch
{
}
}
ScreenShot
