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
<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">
<Columns>
<asp:CommandField
HeaderText="Ops"
ButtonType="Image"
ShowEditButton="true"
EditText="E"
UpdateText="U"
ShowCancelButton="true"
CancelText="X"
ShowDeleteButton="true"
DeleteText="D" />
<asp:BoundField
ReadOnly="true"
DataField="UserName"
HeaderText="UserName" />
<asp:BoundField
DataField="Email"
HeaderText="Contact Email" />
<asp:TemplateField
HeaderText="Role">
<ItemTemplate>
<asp:Label
ID="lblRole"
text="<%# namespace.Admin.getRoleOfUser( ) %>"
runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:CheckBoxField
DataField="IsApproved"
HeaderText="User is Approved" />
<asp:TemplateField
HeaderText="UserLocked">
<ItemTemplate>
<asp:CheckBox
id="grdUsers_lockCheckBox"
Checked='<%# Eval("IsLockedOut") %>'
Enabled="false"
runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button
id="grdUsers_unlockUser"
OnClick="grdUsers_unlockUser"
Text="Unlock"
runat="server" />
<asp:HyperLink
id="grdUsers_lockInfo"
text="?"
onclick='popup("lock_info.html")'
runat="server" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
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.
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;
}