A little trick of the DataGrid

Source: Internet
Author: User
Tags count eval tostring
datagrid| Tips//Add Delete confirmation dialog box:
private void Datagrid1_itemdatabound ()

{
Switch (e.item.itemtype)
{
Case ListItemType.Item:
Case ListItemType.AlternatingItem:
Case ListItemType.EditItem:
ImageButton btn = (ImageButton) e.item.findcontrol ("Btndelete");
Btn. Attributes.Add ("onclick", "return Confirm") (' Are you sure you want to delete this record?] ');");
Break

}
}
Processing action:
private void Datagrid1_itemcommand ()
{
String C=e.commandname;
int permissionsid = (int) this. Datagrid1.datakeys[e.item.itemindex];//datakeyfield value
Switch (c)
{
Case "Delete":
Perform a delete operation
Break

}

}

There's a good way:
datagrid-Property Builder-Column-"Add button Column-delete-" text (T)-> in the text box plus:

<div id= "de" onclick= "javascript:return confirm (' OK delete? ') ' > Delete </div>

It's OK.
Ok!


Re-value assignment:

private void Datagrid1_itemdatabound ()
{
if ((E.item.itemtype==listitemtype.item) | | (E.item.itemtype==listitemtype.alternatingitem))
{
E.item represents a line

String imgurl = (string) DataBinder.Eval (e.Item.DataItem, "ImageUrl");
Note This line, what type of "ImageUrl" field is turned into before, otherwise the error

E.item.cells[0]. Style.add ("Font-weight", "bold");
E.item.cells[0]. ForeColor = System.Drawing.Color.Red;
E.item.backcolor = System.Drawing.Color.AliceBlue;


String s=e.item.dataitem.tostring ();
String Ss=e.item.cells[0]. Text;
int sss=e.item.cells.count;

}
}


The binding is the recalculation of the number of pages with the current page

public void Datashowbind (DataSet ds)
{
This. Datagrid1.datasource=ds;
if (ds. TABLES.COUNT&GT;0)
{
int Rowscount=ds. Tables[0]. Rows.Count;
Double p=double. Parse (Rowscount. ToString ())/5.0;
Note: Only double/double result is double,int/int=int;

int Newpagecount=int. Parse (Math.ceiling (P). ToString ());

if (this. DATAGRID1.CURRENTPAGEINDEX&GT;NEWPAGECOUNT-1)
{
This. datagrid1.currentpageindex--;
}

This. Datagrid1.databind ();
}


}

The events of the controls in the column are first raised to the Datagrid1_itemcommand event, but to determine the CommandName
private void Topicsgrid_itemcommand (E)
{
String Btn=e.commandname;
int i=0;
Switch (BTN)
{
Case "Edit":
i= (int) this. Topicsgrid.datakeys[e.item.itemindex];
Break
Case "Delete":
i= (int) this. Topicsgrid.datakeys[e.item.itemindex];

Break
}
}


Click on the Link Column pop-up window

<Columns>
<asp:TemplateColumn>
<ItemTemplate>

<a href= "Javascript:var aa=window.open (' <%#" form2.aspx?id= "+ DataBinder.Eval" (Container.DataItem, "shareholding name")% > ', ', ' width=310,height=280,top=160,left=350 '); Aa.focus (); >
<% #DataBinder. Eval (Container.DataItem, "shareholding name")%>
</a>

</ItemTemplate>
</asp:TemplateColumn>
</Columns>



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.