Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom gridview - bind using non-static function
    text
    copied!<p>I am currently attempting to implement a custom gridview interface to display data from an ObjectDataSource frontend to ASP.net membership. The asp.net code for the gridview is</p> <pre><code> &lt;asp:GridView id="grdUsers" HeaderStyle-cssclass="grid_header" RowStyle-cssclass="row" AlternatingRowStyle-cssclass="alternating" OnRowUpdating="grdUsers_RowUpdating" OnRowDeleting="grdUsers_RowDeleting" OnRowCancelingEdit="grdUsers_cancelEdit" datasourceid="srcUsers" autogeneratecolumns="false" allowsorting="true" AllowPaging="true" EmptyDataText="No users..." pagesize="9" runat="server"&gt; &lt;Columns&gt; &lt;asp:CommandField HeaderText="Ops" ButtonType="Image" ShowEditButton="true" EditText="E" UpdateText="U" ShowCancelButton="true" CancelText="X" ShowDeleteButton="true" DeleteText="D" /&gt; &lt;asp:BoundField ReadOnly="true" DataField="UserName" HeaderText="UserName" /&gt; &lt;asp:BoundField DataField="Email" HeaderText="Contact Email" /&gt; &lt;asp:TemplateField HeaderText="Role"&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="lblRole" text="&lt;%# namespace.Admin.getRoleOfUser( ) %&gt;" runat="server" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:CheckBoxField DataField="IsApproved" HeaderText="User is Approved" /&gt; &lt;asp:TemplateField HeaderText="UserLocked"&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox id="grdUsers_lockCheckBox" Checked='&lt;%# Eval("IsLockedOut") %&gt;' Enabled="false" runat="server" /&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;asp:Button id="grdUsers_unlockUser" OnClick="grdUsers_unlockUser" Text="Unlock" runat="server" /&gt; &lt;asp:HyperLink id="grdUsers_lockInfo" text="?" onclick='popup("lock_info.html")' runat="server" /&gt; &lt;/EditItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>My code is currently dying because the function get roleOfUser() is a public function. Preferably I would like to pass a string of the UserName (pulled from the second cell of the GridView) to this function but that I am not sure of, as well as how to call this non-static function as I don't know how to instantiate it from the asp.net code.</p> <pre><code> public string getRoleOfUser( ) { GridView users = (GridView)admin.FindControlRecursive(Page, "grdUsers"); Int32 i = users.EditIndex; GridViewRow userRow = users.Rows[i]; return userRow.Cells[1].Text; } private Control FindControlRecursive(Control root, string id) { if (root.ID == id) { return root; } foreach (Control c in root.Controls) { Control t = FindControlRecursive(c, id); if (t != null) { return t; } } return null; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload