How can I attach detail link to datagrid view column which I fill dynamically from a web service?

32 Views Asked by At

I fill data grid as follows: I took data from a webservice and fill gridview on the aspx file; I want to make ADVERTISEMENTNO column "a link" which shows details of Ad on the screen

public DataTable SgkTecrubeTabloOlustur(System.Collections.Generic.List<IstSgk4AHizmetBilgisiModel> listSgkTecrube)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ADVERTISEMENTNO", typeof(string));
        dt.Columns.Add("ADNAME", typeof(string));
        dt.Columns.Add("ADCODE", typeof(string));
        dt.Columns.Add("BEGINDATE", typeof(string));
        dt.Columns.Add("ENDDATE", typeof(string));


        for (int index = 0; index < listSgkTecrube.Count; index++)
        {
            DataRow row = dt.NewRow();
            if (listSgkTecrube.ToArray()[index].ADVERTISEMENTNO!= null)
            {
                row[0] = listSgkTecrube.ToArray()[index].ADVERTISEMENTNO.ToString();
            }
            if (listSgkTecrube.ToArray()[index].ADNAME != null)
            {
                row[1] = listSgkTecrube.ToArray()[index].ADNAME.ToString();
            }
            if (listSgkTecrube.ToArray()[index].ADCODE!= null)
            {
                row[2] = listSgkTecrube.ToArray()[index].ADCODE.ToString();
            }
         
            if (listSgkTecrube.ToArray()[index].BEGINDATE!= null && !listSgkTecrube.ToArray()[index].BEGINDATE.ToString().Substring(0, 10).Equals("01.01.0001"))
            {
                row[5] = listSgkTecrube.ToArray()[index].BEGINDATE.ToString().Substring(0,10);
            }
            if (listSgkTecrube.ToArray()[index].ENDDATE != null && !listSgkTecrube.ToArray()[index].ENDDATE.ToString().Substring(0, 10).Equals("01.01.0001"))
            {
                row[6] = listSgkTecrube.ToArray()[index].ENDDATE.ToString().Substring(0, 10);
            }
            dt.Rows.Add(row);
        }
        return dt;
    }

my aspx file is as follows:

      <iskurControls:IskurGridView runat="server"
                ID="ctlGridSgkTecrube"
                AutoGenerateColumns="False"
                EmptyDataText="Tecrübe Bilginiz Bulunmamaktadır."
                EnableViewState="true"
                CssClass="table table-bordered table-condensed text-small">
                <Columns>
                    <asp:BoundField DataField="ADVERTISEMENTNO" HeaderText="Ad No">
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="ADNAME" HeaderText="AdName">
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:BoundField>

I can use

    <Columns>
                    <asp:TemplateField HeaderText="" ItemStyle-HorizontalAlign="left">

                        <%-- <HeaderTemplate>
                            <asp:Label ID="ctlIlanSayisi" runat="server"></asp:Label>
                        </HeaderTemplate>--%>

                        <ItemTemplate>
                            <div style="padding-top: 3px; padding-bottom: 3px;">
                                <asp:LinkButton ID="ctlPozisyonMeslekDL" runat="server" UseSubmitBehavior="False" Font-Bold="True"></asp:LinkButton>
                                &nbsp;
                                <asp:Image ID="ctlEngelGif" runat="server" Visible="false" ImageUrl='<%# GetImageUrlByStatus(Eval("PRMSOSYALDURUMKAYITNO").ToString()) %>' />
                            </div>

and my RowDataBound is as follows:

    protected void ctlGridAcikIslerListeDetail_RowDataBound(object sender, GridViewRowEventArgs e)
    {  
        Control ctl = e.Row.FindControl("ctlPozisyonMeslekDL");
        if (ctl != null)
        {
            Literal literal = (Literal)ctl;

            object obj = DataBinder.GetPropertyValue(e.Row.DataItem, "ADVERTISEMENTNO");

            if (obj == null || Convert.IsDBNull(obj))
                literal.Text = "Detay";
            else if (SecurityContext.IsUser && SecurityContext.CurrentUser != null && SecurityContext.CurrentUser.IsInternalUser)
            {
                string userId = CurrentQueryHashedUserID;
                if (string.IsNullOrEmpty(userId))
                    literal.Text = string.Format("<a href=\"javascript:PopupJobDetails('{0}',{1});\">{0}</a>", obj, IsAuthenticated ? 1 : 0);                    
            }
        }              

but the problem is how can ı get ADVERTISMENTNO field as a value from grid ?

0

There are 0 best solutions below