Click here to Skip to main content
16,018,916 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello can anyone help me with how to display a button in listview from codebehind... wht all to write plzz help me out...

thanks all for the help...
Posted

Try this

C#
Button b = new Button();
            b.Name = "Some Name";
            b.Text = "Button Text";
            //other setup here
            listView1.Controls.Add( b );
 
Share this answer
 
protected void lstviewcat_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
LinkButton linkBtnSubCat = (LinkButton)e.Item.FindControl("linkBtnSubCat");
//int catid = (int)lstviewcat.DataKeys[e.Item.DataItemIndex].Value;
//string catid = linkBtnSubCat.CommandArgument;
int catid = Convert.ToInt32(linkBtnSubCat.CommandArgument);
// SubCat_Click(catid);
ListView SubCategory = (ListView)e.Item.FindControl("SubCategory");
SubCategory.DataSource = balObj.Getsubcat(catid);
SubCategory.DataBind();
LinkButton linkbtnsubcat = new LinkButton();
SubCategory.Controls.Add(linkbtnsubcat);

if (SubCategory.HasControls())
{
// linkbtnsubcat.Visible = true;
// linkbtnsubcat.Style.Value = "ADD";
linkbtnsubcat.Text = "ADD SUB-CATEGORY";
//linkbtnsubcat.Width = 100;
linkbtnsubcat.Enabled = true;
//linkbtnsubcat.OnClientClick = "add_new_subcat.aspx";
linkbtnsubcat.PostBackUrl = "add_new_subcat.aspx";

}
}

}

here balobj means i have a separate class...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900