zienur Publish time 2-3-2012 09:13 AM

dynamic column in gridview

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/839/adelink.jpg/ 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...

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

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

                        <asp:TemplateField HeaderStyle-BackColor="#9DCEFF"
                              HeaderText="Status Masuk">
                              <ItemTemplate>
                                  <asp:LinkButton ID="masuk" runat="server"
                                    CommandArgument='<%# DataBinder.Eval(Container,"DataItem.statusin")%>'
                                    CommandName="masuk" Text='<%# Eval("statusin")%>'>
                            </asp:LinkButton>
                              </ItemTemplate>
                              <HeaderStyle BackColor="#3399cc" />
                              <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Center" />
                        </asp:TemplateField>
                        
                        
                        <asp:BoundField DataField="raidin" HeaderText="Catatan Masuk" readonly="true"
                              Visible="true">
                        <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Left" />
                        </asp:BoundField>
                        <asp:BoundField DataField="approvalin" HeaderText="Catatan Kelulusan" readonly="true"
                              Visible="true">
                        <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Left" />
                        </asp:BoundField>
                        
                        <asp:BoundField DataField="dateout" HeaderStyle-BackColor="#9DCEFF"
                              HeaderText="Tarikh Keluar" readonly="true" Visible="true">
                        <HeaderStyle BackColor="#9DCEFF" />
                        <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:BoundField DataField="eventdate2" HeaderStyle-BackColor="#9DCEFF"
                              HeaderText="Hari" readonly="true" Visible="true">
                        <HeaderStyle BackColor="#9DCEFF" />
                        <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:TemplateField HeaderStyle-BackColor="#9DCEFF" HeaderText="Masa Keluar">
                              <ItemTemplate>
                                  <asp:Label ID="lblKeluar" runat="server"><%# DataBinder.Eval(Container, "DataItem.timeout")%></asp:Label>
                              </ItemTemplate>
                              <HeaderStyle BackColor="#9DCEFF" />
                              <ItemStyle BackColor="#E5E5E5" HorizontalAlign="Center" />
                        </asp:TemplateField>
                           <asp:TemplateField HeaderStyle-BackColor="#9DCEFF"
                              HeaderText="Status Keluar">
                              <ItemTemplate>
                                  <asp:LinkButton ID="keluar" runat="server"
                                    CommandArgument='<%# DataBinder.Eval(Container,"DataItem.statusin")%>'
                                    CommandName="masuk" Text='<%# Eval("statusout")%>'>
                            </asp:LinkButton>
                              </ItemTemplate>
                              <HeaderStyle BackColor="#9DCEFF" />
                              <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Center" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="raidout" HeaderStyle-BackColor="#9DCEFF"
                              HeaderText="Catatan Keluar" readonly="true" Visible="true">
                        <HeaderStyle BackColor="#9DCEFF" />
                        <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Left" />
                        </asp:BoundField>
                        <asp:BoundField DataField="approvalout" HeaderStyle-BackColor="#9DCEFF"
                              HeaderText="Catatan Kelulusan" readonly="true" Visible="true">
                        <HeaderStyle BackColor="#9DCEFF" />
                        <ItemStyle BackColor="#e5e5e5" Font-Size="Smaller" HorizontalAlign="Center" />
                        </asp:BoundField>

                      </Columns>
                      <HeaderStyle BackColor="#3399cc" Font-Bold="True" Width="150px" />
                  </asp:GridView>



mintak tolong sape2 yg penah buat yer... thx

kmkd Publish time 8-3-2012 10:46 AM

language apa ni? .net kah?

meritokrasi Publish time 10-3-2012 12:55 AM

Allah mak, ASP.net :doh3:

zienur Publish time 12-3-2012 10:03 AM

Allah mak, ASP.net
meritokrasi Post at 10-3-2012 00:55 http://mforum2.cari.com.my/images/common/back.gif


    nape?

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

zienur Publish time 12-3-2012 10:07 AM

language apa ni? .net kah?
kmkd Post at 8-3-2012 10:46 http://mforum2.cari.com.my/images/common/back.gif


   yup .net{:mlXD:}

zienur Publish time 12-3-2012 10:28 AM

ni code back-end <asp:TemplateField HeaderStyle-BackColor="#9DCEFF" HeaderText="Masa Keluar">
                              <ItemTemplate>
                                  <asp:Label ID="lblKeluar" runat="server"><%# DataBinder.Eval(Container, "DataItem.timeout")%></asp:Label>
                              </ItemTemplate>
                              <HeaderStyle BackColor="#9DCEFF" />
                              <ItemStyle BackColor="#E5E5E5" HorizontalAlign="Center" />
                        </asp:TemplateField>ni code clientPrivate Sub gv_listing_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv_listing.RowDataBound
      If e.Row.RowType = DataControlRowType.Header Then
            e.Row.Cells(0).Width = Unit.Percentage(10)
            e.Row.Cells(7).Width = Unit.Percentage(10)
            e.Row.Cells(5).Width = Unit.Percentage(10)
            e.Row.Cells(11).Width = Unit.Percentage(10)
            e.Row.Cells(13).Width = Unit.Percentage(10)
      End If

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

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

      If e.Row.RowType = DataControlRowType.DataRow Then

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

            If lbl2.Text <> "OK" Then

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

    End Subini coding tuk jadikan dier mcm dlm gbr ni...
http://imageshack.us/photo/my-images/204/xdelink.jpg/


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...

kmkd Publish time 28-3-2012 05:26 PM

lama tak sentuh masalahnya :lol:

zienur Publish time 28-3-2012 05:38 PM

lama tak sentuh masalahnya
kmkd Post at 28-3-2012 17:26 http://mforum2.cari.com.my/images/common/back.gif


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

mod da lei katup...thx
Pages: [1]
View full version: dynamic column in gridview


ADVERTISEMENT