locked
Preventing clickthrough on a gridview Dynamic data field RRS feed

  • Question

  • User-10017267 posted

    I have added dynamic data to a few columns of a gridiew, but I want to prevent clickthough into the table

    How do I make it so that the gridview does not allow clickthrough for that column?

    The column I'm having issues with is 'BundleType'

    see gridview below:

                        <asp:GridView ID="BundleGridView" runat="server" AutoGenerateColumns="false" DataSourceID="BundleLinqDataSource"
                            AllowPaging="True" AllowSorting="True" AutoGenerateSelectButton="true"
                            CssClass="DDGridView backgroundWhite" RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6"
                            PageSize="7" ToolTip="Use the select button to select a Bundle" OnSelectedIndexChanged="BundleGridView_SelectedIndexChanged"
                            DataKeyNames="BundleID" OnRowEditing="BundleGridView_RowEditing">
                            <Columns>
                                <asp:DynamicField DataField="BundleName" HeaderText="Bundle name" ReadOnly="true"
                                    SortExpression="BundleName" />
                                <asp:DynamicField DataField="BundleType" HeaderText="Bundle type" ReadOnly="true"   />
                                <asp:DynamicField DataField="Date" HeaderText="Start date" SortExpression="Date" />
                            </Columns>
                            <RowStyle CssClass="td"></RowStyle>
                            <SelectedRowStyle CssClass="DDSelected" />
                            <HeaderStyle CssClass="th"></HeaderStyle>
                            <%--                    <PagerTemplate>
                            <asp:GridViewPager  id="BundleGridViewPager"runat="server" />
                        </PagerTemplate>--%>
                            <EmptyDataTemplate>
                                There are currently no items in this table.
                            </EmptyDataTemplate>
                        </asp:GridView>

    Sunday, September 18, 2011 11:40 PM

Answers

  • User-10017267 posted

    The workaround is to make it a boundfield.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 19, 2011 12:22 AM

All replies

  • User-10017267 posted

    The workaround is to make it a boundfield.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 19, 2011 12:22 AM
  • User-842507885 posted

    Dear friend,

    Here I am giving you a sample code, please go accordingly. If any question plz ask.

    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //string[] arr = { "1","12" };
            //Readtextfile.Main(arr);
    
            System.Data.DataTable tbl = new DataTable();
            DataColumn col = new DataColumn("One");
            tbl.Columns.Add(col);
            col = new DataColumn("Two");
            tbl.Columns.Add(col);
    
            DataRow dr = tbl.NewRow();
            dr["One"] = " Row 1 Col 1";
            dr["Two"] = " Row 1 Col 2";
            tbl.Rows.Add(dr);
    
            dr = tbl.NewRow();
            dr["One"] = " Row 2 Col 1";
            dr["Two"] = " Row 2 Col 2";
            tbl.Rows.Add(dr);
    
            GridView1.DataSource = tbl;
            GridView1.DataBind();
    
    
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                GridViewRow tr = e.Row;
                tr.Attributes.Add("onClick", "javascript:selectMe(this);");
                tr.Attributes.Add("style", "cursor:hand;");
            }
        }
    }
    Monday, September 19, 2011 3:20 AM