How bind the IMAGE BTTON IN ASP.NET

K011gusain89
Posted by K011gusain89 under C# category on | Points: 40 | Views : 1225
asp code

<asp:DataList ID="DataList1" runat="server" BorderStyle="Inset">

<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510"/><HeaderStyle BackColor="#A55129" Font-Bold="True" Font-Size="Large" ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<ItemTemplate>
<div>
<asp:ImageButton ID="Image1" ImageUrl='<%# Bind("like_pic", "~/upload/{0}") %>' runat="server" CommandArgument='<%#Eval("id")%>' CommandName="like"/>
</div>
</ItemTemplate>
</asp:DataList>

C#

SqlConnection con = new SqlConnection("Server=Servername-PC;Database=databasename;integrated security=true");
int count;
int i = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack != true)
{
bindData();

}
}

void bindData()
{
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = con;
cmd1.CommandText = "select * from Tb_name ";
cmd1.Connection.Open();
SqlDataReader rdr1 = cmd1.ExecuteReader();
DataList1.DataSource = rdr1;
cmd1.Connection.Close();
}

Comments or Responses

Login to post response