CARI Infonet

 Forgot password?
 Register

ADVERTISEMENT

View: 2434|Reply: 7

dynamic column in gridview

[Copy link]
Post time 2-3-2012 09:13 AM | Show all posts |Read mode
Post Last Edit by zienur at 2-3-2012 09:15

salam sume forumer hebat dlm cari ni....
saya ni nk bt gridview... ape2 proses @ edit @ tmbh dlm gridview tu saya tau la nk buat cane...
ade satu ni saya xtau @ xdek idea nk buat...

saya nk buat dlm gridview tu... bile status <> "OK" ... barulah field tu jd hyperlink field... kalo x.. dier jd label biasa...

mcm dlm gbr ni...

http://imageshack.us/photo/my-images/839/adelink.jpg/  ni yg xjd sbb sy yg buat...


http://imageshack.us/photo/my-images/204/xdelink.jpg/ ni yg sy perlu buat...


koding dier mcm ni...saya da letak kan siap2 hyperlink tuh... tp xdek idea cane nk ubah dier according to my coding...

  1. <asp:GridView ID="gv_listing" runat="server"
  2.                       AutoGenerateColumns="False" DataKeyNames="datein"
  3.                       HeaderStyle-BackColor="#3399cc" HeaderStyle-Font-Bold="true"
  4.                       HeaderStyle-Font-Names="Corbel" HeaderStyle-Font-Size="Small"
  5.                       HeaderStyle-Height="30" PageSize="30" Width="100%">
  6.                       <PagerSettings Visible="False"/>
  7.                       <Columns>
  8.                         

  9.                           <asp:TemplateField HeaderText="Masa Masuk">
  10.                               <ItemTemplate>
  11.                                   <asp:Label ID="lblMasuk" runat="server"><%# DataBinder.Eval(Container, "DataItem.timein")%></asp:Label>
  12.                               </ItemTemplate>
  13.                               <ItemStyle BackColor="#E5E5E5" HorizontalAlign="Center" />
  14.                           </asp:TemplateField>

  15.                           <asp:TemplateField HeaderStyle-BackColor="#9DCEFF"
  16.                               HeaderText="Status Masuk">
  17.                               <ItemTemplate>
  18.                                   <asp:LinkButton ID="masuk" runat="server"
  19.                                       CommandArgument='<%# DataBinder.Eval(Container,"DataItem.statusin")%>'
  20.                                       CommandName="masuk" Text='<%# Eval("statusin")%>'>
  21.                             </asp:LinkButton>
  22.                               </ItemTemplate>
  23.                               <HeaderStyle BackColor="#3399cc" />
  24.                               <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Center" />
  25.                           </asp:TemplateField>
  26.                         
  27.                         
  28.                           <asp:BoundField DataField="raidin" HeaderText="Catatan Masuk" readonly="true"
  29.                               Visible="true">
  30.                           <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Left" />
  31.                           </asp:BoundField>
  32.                           <asp:BoundField DataField="approvalin" HeaderText="Catatan Kelulusan" readonly="true"
  33.                               Visible="true">
  34.                           <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Left" />
  35.                           </asp:BoundField>
  36.                         
  37.                           <asp:BoundField DataField="dateout" HeaderStyle-BackColor="#9DCEFF"
  38.                               HeaderText="Tarikh Keluar" readonly="true" Visible="true">
  39.                           <HeaderStyle BackColor="#9DCEFF" />
  40.                           <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Center" />
  41.                           </asp:BoundField>
  42.                           <asp:BoundField DataField="eventdate2" HeaderStyle-BackColor="#9DCEFF"
  43.                               HeaderText="Hari" readonly="true" Visible="true">
  44.                           <HeaderStyle BackColor="#9DCEFF" />
  45.                           <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Center" />
  46.                           </asp:BoundField>
  47.                           <asp:TemplateField HeaderStyle-BackColor="#9DCEFF" HeaderText="Masa Keluar">
  48.                               <ItemTemplate>
  49.                                   <asp:Label ID="lblKeluar" runat="server"><%# DataBinder.Eval(Container, "DataItem.timeout")%></asp:Label>
  50.                               </ItemTemplate>
  51.                               <HeaderStyle BackColor="#9DCEFF" />
  52.                               <ItemStyle BackColor="#E5E5E5" HorizontalAlign="Center" />
  53.                           </asp:TemplateField>
  54.                            <asp:TemplateField HeaderStyle-BackColor="#9DCEFF"
  55.                               HeaderText="Status Keluar">
  56.                               <ItemTemplate>
  57.                                   <asp:LinkButton ID="keluar" runat="server"
  58.                                       CommandArgument='<%# DataBinder.Eval(Container,"DataItem.statusin")%>'
  59.                                       CommandName="masuk" Text='<%# Eval("statusout")%>'>
  60.                             </asp:LinkButton>
  61.                               </ItemTemplate>
  62.                               <HeaderStyle BackColor="#9DCEFF" />
  63.                               <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Center" />
  64.                           </asp:TemplateField>
  65.                           <asp:BoundField DataField="raidout" HeaderStyle-BackColor="#9DCEFF"
  66.                               HeaderText="Catatan Keluar" readonly="true" Visible="true">
  67.                           <HeaderStyle BackColor="#9DCEFF" />
  68.                           <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Left" />
  69.                           </asp:BoundField>
  70.                           <asp:BoundField DataField="approvalout" HeaderStyle-BackColor="#9DCEFF"
  71.                               HeaderText="Catatan Kelulusan" readonly="true" Visible="true">
  72.                           <HeaderStyle BackColor="#9DCEFF" />
  73.                           <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Center" />
  74.                           </asp:BoundField>

  75.                       </Columns>
  76.                       <HeaderStyle BackColor="#3399cc" Font-Bold="True" Width="150px" />
  77.                   </asp:GridView>
Copy the Code




mintak tolong sape2 yg penah buat yer... thx
Reply

Use magic Report


ADVERTISEMENT


Post time 8-3-2012 10:46 AM | Show all posts
language apa ni? .net kah?
Reply

Use magic Report

Post time 10-3-2012 12:55 AM | Show all posts
Allah mak, ASP.net
Reply

Use magic Report

 Author| Post time 12-3-2012 10:03 AM | Show all posts
Allah mak, ASP.net
meritokrasi Post at 10-3-2012 00:55



    nape?

ok sat yer... aritu da dpt da...
tp part amik data lom pass... nnt sy post koding...
Reply

Use magic Report

 Author| Post time 12-3-2012 10:07 AM | Show all posts
language apa ni? .net kah?
kmkd Post at 8-3-2012 10:46



   yup .net
Reply

Use magic Report

 Author| Post time 12-3-2012 10:28 AM | Show all posts
ni code back-end
  1. <asp:TemplateField HeaderStyle-BackColor="#9DCEFF" HeaderText="Masa Keluar">
  2.                               <ItemTemplate>
  3.                                   <asp:Label ID="lblKeluar" runat="server"><%# DataBinder.Eval(Container, "DataItem.timeout")%></asp:Label>
  4.                               </ItemTemplate>
  5.                               <HeaderStyle BackColor="#9DCEFF" />
  6.                               <ItemStyle BackColor="#E5E5E5" HorizontalAlign="Center" />
  7.                           </asp:TemplateField>
Copy the Code
ni code client
  1. Private Sub gv_listing_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv_listing.RowDataBound
  2.         If e.Row.RowType = DataControlRowType.Header Then
  3.             e.Row.Cells(0).Width = Unit.Percentage(10)
  4.             e.Row.Cells(7).Width = Unit.Percentage(10)
  5.             e.Row.Cells(5).Width = Unit.Percentage(10)
  6.             e.Row.Cells(11).Width = Unit.Percentage(10)
  7.             e.Row.Cells(13).Width = Unit.Percentage(10)
  8.         End If

  9.         Dim a As Integer = gv_listing.Rows.Count
  10.         If e.Row.RowType = DataControlRowType.DataRow Then
  11.            
  12.             Dim lbl As Label = CType(e.Row.Cells(4).FindControl("label"), Label)
  13.             Dim temp As String = lbl.Text
  14.             Dim hpl As HyperLink = Nothing

  15.             If lbl.Text <> "OK" Then
  16.               
  17.                 hpl = New HyperLink()
  18.                 lbl.Text = ""
  19.                 hpl.Text = temp
  20.                 hpl.NavigateUrl = "frm_reason.aspx?id=m&orgId=" & Session("orgid")
  21.                 ' cells<column index that control will be added>
  22.                 e.Row.Cells(4).Controls.Add(hpl)
  23.             End If
  24.         End If

  25.         If e.Row.RowType = DataControlRowType.DataRow Then

  26.             Dim lbl2 As Label = CType(e.Row.Cells(10).FindControl("label2"), Label)
  27.             Dim temp2 As String = lbl2.Text
  28.             Dim hpl2 As HyperLink = Nothing

  29.             If lbl2.Text <> "OK" Then

  30.                 hpl2 = New HyperLink()
  31.                 lbl2.Text = ""
  32.                 hpl2.Text = temp2
  33.                 hpl2.NavigateUrl = "frm_reason.aspx?id=k&orgId=" & Session("orgid")
  34.                 ' cells<column index that control will be added>
  35.                 e.Row.Cells(10).Controls.Add(hpl2)
  36.             End If
  37.         End If

  38.     End Sub
Copy the Code
ini coding tuk jadikan dier mcm dlm gbr ni...
/


so skang stuck pada id yg nk diambil masa user klik pd link tersebut...
sbb bile da debug sume...dier x invoke pon mana2 function cth mcm databound,rowcommand,...etc...
so skang ni sape2 tau cane nk invoke a function to make it able to get userID for each row which was selected...
Reply

Use magic Report

Follow Us
Post time 28-3-2012 05:26 PM | Show all posts
lama tak sentuh masalahnya
Reply

Use magic Report

 Author| Post time 28-3-2012 05:38 PM | Show all posts
lama tak sentuh masalahnya
kmkd Post at 28-3-2012 17:26



   hehehe... pg td baru siap... nth ape la slow sgt sy ni... huhu...neway... thx la komen..hehe

mod da lei katup...thx
Reply

Use magic Report


ADVERTISEMENT


You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT


Forum Hot Topic

 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CARI Infonet

5-5-2024 06:12 AM GMT+8 , Processed in 0.407820 second(s), 33 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list