This is a migrated thread and some comments may be shown as answers.

Itemdatabound doesnt have information when populate grid in NeedDataSource

3 Answers 196 Views
Grid
This is a migrated thread and some comments may be shown as answers.
iomega 55
Top achievements
Rank 1
iomega 55 asked on 17 Jan 2012, 04:55 AM
Hi, I have a grid and I populate its datasource in the NeedDataSource event.

I requiere to modifiy a gridhyperlink column, I need to add an onclick attribute to the link column, but when I

This is the code:

<telerik:RadGrid id="grdPase" Culture="es-MX"
         ShowStatusBar="true"
         runat="server"
         AllowPaging="true"
         AllowSorting="true" AllowNaturalSort="false"
         AutoGenerateColumns="false"
         AllowMultiRowSelection="false"
         OnItemDataBound="grdPase_ItemDataBound"
         OnPreRender="grdPase_PreRender"
         OnNeedDataSource="grdPase_NeedDataSource" >
     <MasterTableView PageSize="15" NoDetailRecordsText="Sin Informacion" NoMasterRecordsText="Sin Informacion">
         <Columns>
             <telerik:GridHyperLinkColumn
             DataTextFormatString="{0:d7}"
             UniqueName="rowno"
             DataTextField="rowno"                       
             HeaderText="Folio" >
             </telerik:GridHyperLinkColumn>

       protected void grdPase_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem _item = (GridDataItem)e.Item;
                HyperLink _link = (HyperLink)_item["rowno"].Controls[0];
                _link.Attributes["href"] = "#";
                _link.Attributes["onclick"] = String.Format("javascript:top.fnOpenWin('PopSPase','Registro de Pases','../01/e01PasePop.aspx?r={0}',true,'wndshow.png',630,550,false,true,36);return false;", _item["rowno"].Text); 
/* _item["rowno"].Text   has always a   value instead of a numeric value */
 
            }
        }
 
        protected void grdPase_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            /*here we have a lot of code for filtering, ordering the information */
             sqlPase.SelectCommand = "SELECT * FROM tbl01Pase" + strFilteringOrderingInformation;
            grdPase.DataSource = sqlPase;
        }

How can I access in the Itemdatabound event the row information?

Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Jan 2012, 05:19 AM
Hello,

I tried the same scenario which worked as expected. The "Text" property returns the DataTextFormatString property set for the HyperLinkColumn.

-Shinu.
0
iomega 55
Top achievements
Rank 1
answered on 17 Jan 2012, 07:48 AM
In my case it doesnt return the value you mention. By the way if I want to retrieve another column value it has also a null value.

Do you have a sample?
0
Jayesh Goyani
Top achievements
Rank 2
answered on 17 Jan 2012, 10:22 AM
Hello iomega 55 ,

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
          OnItemDataBound="RadGrid1_ItemDataBound" OnItemCommand="RadGrid1_ItemCommand"
          OnPreRender="RadGrid1_PreRender">
          <ExportSettings HideStructureColumns="true">
          </ExportSettings>
          <MasterTableView DataKeyNames="ID,Name" CommandItemDisplay="Top">
              <CommandItemSettings ShowExportToExcelButton="true" />
              <Columns>
                  <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
                  </telerik:GridBoundColumn>
                  <telerik:GridHyperLinkColumn DataTextFormatString="{0:d7}" UniqueName="ID" DataTextField="ID"
                      HeaderText="ID">
                  </telerik:GridHyperLinkColumn>
              </Columns>
          </MasterTableView>
      </telerik:RadGrid>
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ID");
            dt.Columns.Add("Name");
            dt.Columns.Add("IsAdd");
             
            dt.Rows.Add(1,"Name1", false);
            dt.Rows.Add(2,"Naem2", false);
            dt.Rows.Add(3,"Name3", false);
            Session["dt"] = dt;
        }
    }
 
 
 
 
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        RadGrid1.DataSource = (DataTable)Session["dt"];
    }
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem _item = (GridDataItem)e.Item;
            HyperLink _link = (HyperLink)_item["ID"].Controls[0];
            _link.Attributes["href"] = "#";
            _link.Attributes["onclick"] = "alert('" + _link.Text +"_"+_item["Name"].Text +"_" + _item.GetDataKeyValue("ID").ToString() + "');";
 
        }
    }
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        
         
    }
 
 
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
     
    }

Let me know if any concern.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
iomega 55
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
iomega 55
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or