Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Can't get the anything from e.Item.Cells[1].Text

Can't get the anything from e.Item.Cells[1].Text

Scheduled Pinned Locked Moved ASP.NET
csharphelpasp-netgraphicsdesign
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dratcha
    wrote on last edited by
    #1

    I am creating an asp.net site with c# as the backend. In this page, I have created a datagrid which uses TemplateColumns instead of BoundColumns. The problem I am having is that when I select a column with the edit button, I can't get a value back from e.Item.Cells[1].Text I can do the same exact thing in VB and it works fine though. Including a code sample which I made just to try and track down the issue. In the below code, I have a delete button that gives a pop-up listing for each e.Item.Cells[x].Text. The BoundColumn works, while the TemplateColumn does not work. Here is the datagrid: <%# DataBinder.Eval(Container.DataItem, "AssetTag") %> And here is the code behind: namespace SUSExemption { using System; using System.Data; using System.Drawing; using System.Web; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using System.Configuration; using System.Web.Mail; /// /// Summary description for ucForm_Admin2. /// public class ucForm_Admin2 : System.Web.UI.UserControl { protected System.Web.UI.WebControls.Label lblUserLogin; protected System.Web.UI.WebControls.TextBox txtUserLogin; protected System.Web.UI.WebControls.Button btnUserSearch; protected System.Web.UI.WebControls.Label lblUserError; protected System.Web.UI.WebControls.Label lblUserName; protected System.Web.UI.WebControls.TextBox txtUserName; protected System.Web.UI.WebControls.Label lblUserManagerLogi

    R 1 Reply Last reply
    0
    • D dratcha

      I am creating an asp.net site with c# as the backend. In this page, I have created a datagrid which uses TemplateColumns instead of BoundColumns. The problem I am having is that when I select a column with the edit button, I can't get a value back from e.Item.Cells[1].Text I can do the same exact thing in VB and it works fine though. Including a code sample which I made just to try and track down the issue. In the below code, I have a delete button that gives a pop-up listing for each e.Item.Cells[x].Text. The BoundColumn works, while the TemplateColumn does not work. Here is the datagrid: <%# DataBinder.Eval(Container.DataItem, "AssetTag") %> And here is the code behind: namespace SUSExemption { using System; using System.Data; using System.Drawing; using System.Web; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using System.Configuration; using System.Web.Mail; /// /// Summary description for ucForm_Admin2. /// public class ucForm_Admin2 : System.Web.UI.UserControl { protected System.Web.UI.WebControls.Label lblUserLogin; protected System.Web.UI.WebControls.TextBox txtUserLogin; protected System.Web.UI.WebControls.Button btnUserSearch; protected System.Web.UI.WebControls.Label lblUserError; protected System.Web.UI.WebControls.Label lblUserName; protected System.Web.UI.WebControls.TextBox txtUserName; protected System.Web.UI.WebControls.Label lblUserManagerLogi

      R Offline
      R Offline
      Ray Williams II
      wrote on last edited by
      #2

      You will need to access the DataBoundLiteralControl[^] in the same manner you have the LinkButton. The templated column is different from the bound column in that is implements the control collection for displaying its contents. In order to access the value of the templated column, you will need to evaluate the appropiate member of its control collection. =============== Sample DataGrid Code

      <asp:DataGrid ID="dgAdmin" Runat="server" DataKeyField="Id" AutoGenerateColumns="False">
      <Columns>
      <asp:BoundColumn DataField="Id" HeaderText="Id" />
      <asp:BoundColumn DataField="Value1" HeaderText="Value1" />
      <asp:BoundColumn DataField="Value2" HeaderText="Value2" />
      <asp:TemplateColumn HeaderText="Delete">
      <ItemTemplate>
      <asp:LinkButton ID="lnkDelete" Runat="server">Delete
      </ItemTemplate>
      </asp:TemplateColumn>
      </Columns>
      </asp:DataGrid>

      =============== Event Code

      private void dgAdmin_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
      {
      if (e.Item.ItemType != ListItemType.EditItem)
      {
      //## First, make sure we're NOT dealing with a Header or Footer row
      if (e.Item.ItemType != ListItemType.Header)
      {
      if (e.Item.ItemType != ListItemType.Footer)
      {
      //## Now, reference the LinkButton control that the Delete ButtonColumn has been rendered to
      System.Web.UI.WebControls.LinkButton deleteButton;
      deleteButton = (LinkButton)e.Item.FindControl("lnkDelete");

      			//## ADDITIONAL CODE
      			System.Web.UI.DataBoundLiteralControl templatedColumn;
      			templatedColumn = (DataBoundLiteralControl)e.Item.Cells\[2\].Controls\[0\];
      
      			//## We can now add the onclick event handler
      			//deleteButton.Attributes\["onclick"\] = "javascript:return confirm('Template Column: " + e.Item.Cells\[1\].Text + " | DataBound Column: " + e.Item.Cells\[2\].Text +"');";
      
      			//## MODIFIED CODE
      			deleteButton.Attributes\["onclick"\] = "javascript:return confirm('Template Column: " + e.Item.Cells\[1\].Text + " | DataBound Column: " + templatedColumn.Text +"');";
      		}
      	}
      }
      

      }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups