Bind columns in the gridview

Source: Internet
Author: User

------------- Front-end gridview --------------------
<Asp: gridview id = "cartgrid" runat = "server" autogeneratecolumns = "false" width = "100%" emptydatatext = "<strong> <center> <font color = 'red'> your the shopping cart is empty! </Font> </center> </strong> "skinid =" shopcargridview "onrowdatabound =" cartgrid_rowdatabound ">

<Columns>

<Asp: templatefield headertext = "select">
<Itemtemplate>
<Input value = '<% # eval ("ID") %> 'name = "choice" type = "checkbox" Checked = "true"/>
</Itemtemplate>
<Itemstyle width = "28px"/>
<Headerstyle width = "28px"/>
</ASP: templatefield>

<Asp: boundfield datafield = "productid" headertext = "item No.">
<Itemstyle horizontalalign = "center" width = "80px"/>
<Headerstyle horizontalalign = "center" width = "80px"/>
</ASP: boundfield>

<Asp: boundfield datafield = "name" headertext = "item name"/>

<Asp: templatefield headertext = "earned points">
<Itemtemplate>
<% # Gettotalscore (eval ("score"). tostring (), Eval ("quantity"). tostring () %>
</Itemtemplate>
<Itemstyle width = "55px"/>
<Headerstyle width = "55px"/>
</ASP: templatefield>

<Asp: templatefield headertext = "transportation fee">
<Itemtemplate>
<% # Eval ("sendprice", "{0: c}") %>
</Itemtemplate>
<Itemstyle width = "55px"/>
<Headerstyle width = "55px"/>
</ASP: templatefield>

<Asp: templatefield headertext = "delivery method">
<Itemtemplate>
<Asp: Label id = "lblsend" runat = "server" text = ""> </ASP: Label>
<% -- <Asp: dropdownlist id = "dropdownlist1" runat = "server">
</ASP: dropdownlist> -- %>
</Itemtemplate>
<Itemstyle width = "60px"/>
<Headerstyle width = "60px"/>
</ASP: templatefield>

<Asp: templatefield headertext = "Order Price">
<Itemtemplate>
<% # Eval ("price", "{0: c}") %>
<Asp: hiddenfield id = "Hdid" value = '<% # eval ("ID") %> 'runat = "server"/>
</Itemtemplate>
<Itemstyle width = "55px"/>
<Headerstyle width = "55px"/>
</ASP: templatefield>

<Asp: templatefield headertext = "quantity">
<Itemtemplate>
<Asp: textbox id = "txtquantity" runat = "server" text = '<% # eval ("quantity ") %> 'width = "30px" maxlength = "6" style = "line-Height: 110%; Background: #374e98; color: White" onblur = "test (this. value); "> </ASP: textbox> <asp: regularexpressionvalidator id = "rquantity" runat = "server" errormessage = "The number can only be a positive integer" controltovalidate = "txtquantity" setfocusonerror = "true" validationexpression = "^ [1-9] \ * $ "> * </ASP: regularexpressionvalidator>
</Itemtemplate>
<Itemstyle width = "40px" verticalalign = "Middle"/>
<Headerstyle width = "40px"/>
</ASP: templatefield>

<Asp: templatefield headertext = "subtotal">
<Itemtemplate>
<% # Gettotalpriceex (eval ("price"). tostring (), Eval ("quantity"). tostring (), Eval ("sendprice"). tostring () %>
</Itemtemplate>
<Itemstyle width = "40px"/>
<Headerstyle width = "40px"/>
</ASP: templatefield>
<Asp: templatefield headertext = "operation">
<Itemtemplate>
<A href = "shopcar. aspx? Action = Delete & id = <% # eval ("ID") %> "onclick =" Return confirm ('Are you sure you want to delete this item from the cart? ') "> <Span style = 'color: Blue'> Delete </span> </a> | <a href =" fav. aspx? Action = add & productid = <% # eval ("ID") %> "onclick =" Return confirm ('add this item to favorites? ') "> <Span style = 'color: Blue'> favorites </span> </a>
</Itemtemplate>
<Itemstyle width = "60px"/>
<Headerstyle width = "60px"/>
</ASP: templatefield>

</Columns>

</ASP: gridview>

---------------- Backend CS file binding -------------------------

Protected void bindshoppingcart ()
{
Database DB = new database ();
Conn = dB. getconn ();
String SQL = "select * From v_order ";
Sqldatareader SDR = dB. runsql (SQL, Conn );
Cartgrid. datasource = SDR;
Cartgrid. databind ();
SDR. Close ();
DB. Dispose (conn );
}

 

Protected void cartgrid_rowdatabound (Object sender, gridviewroweventargs E)
{
If (E. Row. findcontrol ("Hdid ")! = NULL)
{
Hiddenfield HH1 = (hiddenfield) E. Row. findcontrol ("Hdid ");

String getsendmethodbyid = hh1.value. tostring ();

Conn = dB. getconn ();

String SQL = "select f_sendwayname, f_sendmethodid from v_productsendway where (f_productid = '" + getsendmethodbyid + "')";

Sqldatareader myreader = dB. runsql (SQL, Conn );

dropdownlist DDL = (dropdownlist) E. Row. findcontrol ("dropdownlist1");

label LBL = (Label) E. row. findcontrol ("lblsend");
LBL. TEXT = ""; while (myreader. read () { LBL. text + = "" + myreader [0]. tostring () + ""; }< br> LBL. text + = "";
myreader. close ();
}< BR >}

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.