We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

krisdb on 04/10/08


Tagged

c -sharp


Versions (?)


GridView stuff


Published in: C# 


  1. <asp:GridView
  2. id="gvGridView"
  3. runat="server"
  4. AutoGenerateColumns="False"
  5. >
  6. <Columns>
  7.  
  8. </Columns>
  9. </asp:GridView>
  10.  
  11. gvGridView.DataSource = dtDataTable;
  12. gvGridView.DataBind();
  13.  
  14. <asp:TemplateField>
  15. <ItemTemplate>
  16. <a href='default.aspx?cid=<%# Eval("id") %>&sid=<%=Request.QueryString["id"].ToString()%>'><%# Eval("Column") %></a>
  17. </ItemTemplate>
  18. </asp:TemplateField>
  19.  
  20.  
  21. <asp:BoundField DataField="" HeaderText="" HtmlEncode="false" DataFormatString="{0:MM/dd/yyyy}" SortExpression="" />
  22.  
  23. <asp:HyperLinkField
  24. DataNavigateUrlFields="ID"
  25. DataTextFormatString="{0}"
  26. DataNavigateUrlFormatString="default.aspx?id={0}"
  27. DataTextField=""
  28. HeaderText=""
  29. />
  30.  
  31. <asp:TemplateField HeaderText="Name">
  32. <ItemTemplate>
  33. <asp:HyperLink ID="hlName" runat="server" NavigateUrl='<%# ("page.aspx?id=" + Eval("ID")) %>' />
  34. </ItemTemplate>
  35. </asp:TemplateField>
  36.  
  37. <asp:LinkButton
  38. ID="lbButton"
  39. CommandArgument='<%# Eval("ID") %>'
  40. OnCommand="gvCommand_Command"
  41. Text=""
  42. runat="server"
  43. />
  44.  
  45.  
  46. CONFIRM DELETE:
  47.  
  48. OnRowDataBound="GridView_RowDataBound"
  49.  
  50. <asp:TemplateField>
  51. <ItemTemplate>
  52.  
  53. <asp:LinkButton
  54. ID="lbDelete"
  55. CommandArgument='<%# Eval("id") %>'
  56. OnCommand="lbDelete_Command"
  57. Text="Delete"
  58. runat="server"
  59. />
  60. </ItemTemplate>
  61. </asp:TemplateField>
  62.  
  63.  
  64. protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
  65. {
  66. if (e.Row.RowType == DataControlRowType.DataRow)
  67. {
  68. //e.Row.Attributes.Add("onmouseover", "Highlight(this);");
  69. //e.Row.Attributes.Add("onmouseout", "resetColorRows();");
  70.  
  71. LinkButton lbDelete = (LinkButton)e.Row.FindControl("lbDelete");
  72.  
  73. if (lbDelete != null)
  74. {
  75. DataRowView drv = (DataRowView)e.Row.DataItem;
  76.  
  77. if (drv["Name"] != null)
  78. lbDelete.Attributes.Add("onclick", "return confirm('Are you sure you want to delete \\'" + drv["Name"].ToString().ToUpper() + "\\'');");
  79. }
  80. }
  81. }

Report this snippet 

You need to login to post a comment.