Custom binding of the gridview control to respond to the template column button event

Source: Internet
Author: User

-- Merchant Brand Management

<Asp: gridView ID = "GridViewBrand" CellPadding = "0" CellSpacing = "1" runat = "server" AutoGenerateColumns = "False" GridLines = "None" Width = "98%" OnRowDataBound = "GridViewBrand_RowDataBound ">
<Columns>
<Asp: BoundField DataField = "BrandID" HeaderText = "no.">
<HeaderStyle CssClass = "gdv"/>
<ItemStyle HorizontalAlign = "Center" CssClass = "gdvRow2"/>
</Asp: BoundField>
<Asp: BoundField DataField = "BrandName" HeaderText = "brand name">
<HeaderStyle CssClass = "gdv"/>
<ItemStyle HorizontalAlign = "Center" CssClass = "gdvRow2"/>
</Asp: BoundField>
<Asp: BoundField DataField = "ManufacturerName" HeaderText = "manufacturer">
<HeaderStyle CssClass = "gdv"/>
<ItemStyle HorizontalAlign = "Center" CssClass = "gdvRow2"/>
</Asp: BoundField>
<Asp: TemplateField HeaderText = "add a brand to a seller">
<ItemTemplate>
<Asp: button ID = "btn_CreateDealerBrand" Text = "add this brand to sellers" DealerID = "0" BrandID = "0" runat = "server" OnClick = "CreateDealerBrand" CssClass = "istop1" onClientClick = "return confirm ('to join the brand? ') "/>
</ItemTemplate>
<HeaderStyle CssClass = "gdv"/>
<ItemStyle HorizontalAlign = "Center" CssClass = "gdvRow2"/>
</Asp: TemplateField>
</Columns>
</Asp: GridView>

Event background Code (Part ):

GridViewBrand_RowDataBound event (which can be defined in the property event of the gridview Control)

Protected void GridViewBrand_RowDataBound (object sender, GridViewRowEventArgs e)
{
If (e. Row. RowIndex> = 0)
{
String brandIDStr = e. Row. Cells [0]. Text;
String brandNameStr = Server. HtmlDecode (e. Row. Cells [1]. Text). ToString ();
Button btn_CreateDealerBrand = (Button) e. Row. Cells [3]. FindControl ("btn_CreateDealerBrand ");
Btn_CreateDealerBrand.Attributes ["BrandID"] = brandIDStr;
Btn_CreateDealerBrand.Attributes ["DealerID"] = dealer. DealerID. ToString ();
Btn_CreateDealerBrand.Text = "add brand to seller [" + dealer. UserName + "] [" + brandNameStr + "]";
Btn_CreateDealerBrand.OnClientClick = "return confirm ('add brand to seller [" + dealer. UserName + "] [" + brandNameStr + "]? ')";
}
}

CreateDealerBrand

Protected void CreateDealerBrand (object sender, EventArgs e)
{
// Permission: System Administrator and total Administrator
If (managerClient. ManagerType! = 1 & managerClient. ManagerType! = 2)
{
Response. Write ("Sorry! Contact the administrator. ");
Response. End ();
}
Button button = (Button) sender;
Home. Function. DealersBrand dealerBrand = new Home. Function. DealersBrand ();
DealerBrand. BrandID = int. Parse (button. Attributes ["BrandID"]. ToString ());
DealerBrand. DealerID = int. Parse (button. Attributes ["DealerID"]. ToString ());
DealerBrand. IsValid = 1;
DealerBrand. Create ();
If (dealerBrand. DealerBrandID = 0)
AlertMsg = "<script type = \" text/javascript \ "> alert (\" this seller already has this brand! \ "); </Script> ";
GridViewDatabind ();
GridView_DealerBrandDatabind ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.