English 中文(简体)
从浏览中的链接中获取电网格浏览细节
原标题:getting gridview row details from a link in the row

我有一个电离层表,分三栏。 只有档案所有人才能删除档案。 我如何证实,删除档案的人是档案的所有人。 我有徽章的全权证书,我有上载的By式插座。 我可以拿到日志,但我无法上载。 删除链接栏中点击。

<asp:TemplateField HeaderText="View" ItemStyle-HorizontalAlign="Center">
        <ItemTemplate>
          <asp:HyperLink ID="lnkView" runat="server" NavigateUrl= <%# Eval("Id", "~/ViewFile.aspx?Id={0}") %>  Text="View"></asp:HyperLink>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:HyperLinkField ItemStyle-HorizontalAlign="Center" DataNavigateUrlFields="Id" DataNavigateUrlFormatString="~/DeleteFile.aspx?Id={0}" HeaderText="Delete" Text="Delete" />

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {        
     switch (e.Row.RowType)
    {
      case DataControlRowType.DataRow:
        FileInfo myFileInfo = (FileInfo)e.Row.DataItem;
        switch (myFileInfo.ContentType.ToLower())
        {
          case "image/pjpeg":         // .jpg files
          case "image/gif":           // .gif files
          case "application/msword":  // .doc files
          case "text/plain":         // .txt files 
          case "application/vnd.ms-excel":  
            // Do nothing. When the row contains a viewable type, 
            // we want the View link to be enabled.
            break;
          default:
            // Find the View link and disable it.
            HyperLink myLink = (HyperLink)e.Row.FindControl("lnkView");
            myLink.Enabled = false;
            break;
        }
        break;
    }
  }
最佳回答

You can use the RowDataBound event and check UpdatedBy with the Current logined user. If it is not the same user, simply hide the delete button.

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        System.Data.DataRow dr = ((System.Data.DataRowView)e.Row.DataItem).Row;

        if (dr["uploadedBy"].ToString() != HttpContext.Current.User.Identity.Name)
        {
            ((Button)e.Row.FindControl("btnDelete")).Visible = false;
        }
     }
 }
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签