0

I have a gridview that have a column that I want show It dynamically: If IsExpert or IsAgent equal true show It else not show It and I don't want use RowBoundData.(IsExpert and IsAgent are server side property)

MyCode:

<asp:GridView ID="grvTicketList" runat="server" AllowPaging="True" AutoGenerateColumns="False" CssClass="table half table-hover table-mc-light-blue" GridLines="None"
EmptyDataText="تیکتی موجود نیست" OnPageIndexChanging="grvTicketList_PageIndexChanging" PagerStyle-BackColor="White"
PagerStyle-ForeColor="Black" OnRowCommand="grvTicketList_RowCommand" >
<Columns>

    <asp:BoundField DataField="TicketID" ReadOnly="true" HeaderText="شماره تیکت" />
    <asp:BoundField DataField="CurrentStateId" ReadOnly="true" HeaderText="شماره مرحله فعلی تیکت" />
    <asp:BoundField DataField="TrackingCode" ReadOnly="true" HeaderText="کد رهگیری" />
    <asp:BoundField DataField="ServiceName" ReadOnly="true" HeaderText="نام خدمت" />
    <asp:BoundField DataField="SubServiceName" ReadOnly="true" HeaderText=" نام زیر خدمت" />
    <asp:BoundField DataField="strTicketDate" HeaderText="زمان ثبت تیکت" />
    <asp:BoundField DataField="CustomerName" HeaderText=" نام و نام خانوادگی مشتری" />
    <asp:BoundField DataField="StateName" HeaderText="وضعیت تیکت" />
    <asp:BoundField DataField="UserName" HeaderText="نام ثبت کننده تیکت" />

    <asp:ButtonField Text="بازخورد" CommandName="FeedBack" ButtonType="Link" >
        <ItemStyle ForeColor="#003399" />
    </asp:ButtonField>

</Columns>

<PagerStyle BackColor="White" ForeColor="Black"></PagerStyle>

4
  • Why not RowDataBound ? Commented Dec 7, 2015 at 12:31
  • I am assuming IsExpert and IsAgent is a property in you code. why don't you hide the gridview in Page_Load, otherwise use Jquery. Commented Dec 7, 2015 at 12:32
  • @Zaki Yes! IsExpert and IsAgent are property (bool type) but I need server code.and want visible or invisible ButtonField column Commented Dec 7, 2015 at 12:34
  • @MattMurdock Because I have another event that causes after page postback disappear changes on RowDataBound Commented Dec 7, 2015 at 12:39

2 Answers 2

1

In page load

if(IsExpert || IsAgent)
    GridView1.Columns[9].Visible=true;
 else
    GridView1.Columns[9].Visible=false;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks.. But 'IsExpert' or 'IsAgent' are server side property(bool type)
0

Instead of using aspx i would prefer codebehind, for example Page_Load or DataBound. Note that DataBound is only triggered once as opposed to RowDataBound which is fired for every row:

codebehind:

protected void GrvTicketList_DataBound(Object sender, EventArgs e)
{
    GridView grid = (GridView)sender;
    grid.Columns[9].Visible = IsExpert || IsAgent;
}

aspx (add the event handler):

<asp:GridView ID="grvTicketList" OnDataBound="GrvTicketList_DataBound" runat="server" AllowPaging="True" AutoGenerateColumns="False" CssClass="table half table-hover table-mc-light-blue" GridLines="None"
EmptyDataText="تیکتی موجود نیست" OnPageIndexChanging="grvTicketList_PageIndexChanging" PagerStyle-BackColor="White"
PagerStyle-ForeColor="Black" OnRowCommand="grvTicketList_RowCommand" >
<Columns>

    <asp:BoundField DataField="TicketID" ReadOnly="true" HeaderText="شماره تیکت" />
    <asp:BoundField DataField="CurrentStateId" ReadOnly="true" HeaderText="شماره مرحله فعلی تیکت" />
    <asp:BoundField DataField="TrackingCode" ReadOnly="true" HeaderText="کد رهگیری" />
    <asp:BoundField DataField="ServiceName" ReadOnly="true" HeaderText="نام خدمت" />
    <asp:BoundField DataField="SubServiceName" ReadOnly="true" HeaderText=" نام زیر خدمت" />
    <asp:BoundField DataField="strTicketDate" HeaderText="زمان ثبت تیکت" />
    <asp:BoundField DataField="CustomerName" HeaderText=" نام و نام خانوادگی مشتری" />
    <asp:BoundField DataField="StateName" HeaderText="وضعیت تیکت" />
    <asp:BoundField DataField="UserName" HeaderText="نام ثبت کننده تیکت" />

    <asp:ButtonField Text="بازخورد" CommandName="FeedBack" ButtonType="Link" >
        <ItemStyle ForeColor="#003399" />
    </asp:ButtonField>

</Columns>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.