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>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>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>