Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1031677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:58:00+00:00 2026-05-16T13:58:00+00:00

I have a GridView in my page : <asp:GridView ID=GridView1 runat=server AllowPaging=True BackColor=White AutoGenerateColumns=False

  • 0

I have a GridView in my page :

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" BackColor="White"
    AutoGenerateColumns="False" EmptyDataText="No data available." BorderColor="#DEDFDE"
    BorderStyle="None" BorderWidth="1px" CellPadding="4" Width="729px" ForeColor="Black"
    GridLines="Vertical" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
    <RowStyle BackColor="#F7F7DE" />
    <Columns>
        <asp:TemplateField HeaderText="TransactionKey" SortExpression="TransactionKey">
            <EditItemTemplate>
                <asp:TextBox ID="TextBoxGridViewTransactionKey" runat="server" Text='<%# Bind("TextBoxTransactionKey") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="LabelGridViewTransactionKey" runat="server" Text='<%# Bind("TextBoxTransactionKey") %>'></asp:Label>
            </ItemTemplate>
            <HeaderStyle Font-Size="14px" />
            <ItemStyle Font-Size="12px" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="TerminalID" SortExpression="TerminalID">
            <EditItemTemplate>
                <asp:TextBox ID="TextBoxGridViewTerminalID" runat="server" Text='<%# Bind("TextBoxTerminalID") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="LabelGridViewTerminalID" runat="server" Text='<%# Bind("TextBoxTerminalID") %>'></asp:Label>
            </ItemTemplate>
            <HeaderStyle Font-Size="14px" />
            <ItemStyle Font-Size="12px" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="MerchantID" SortExpression="MerchantID">
            <EditItemTemplate>
                <asp:TextBox ID="TextBoxGridViewMerchantID" runat="server" Text='<%# Bind("TextBoxMerchantID") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="LabelGridViewMerchantID" runat="server" Text='<%# Bind("TextBoxMerchantID") %>'></asp:Label>
            </ItemTemplate>
            <HeaderStyle Font-Size="14px" />
            <ItemStyle Font-Size="12px" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="شماره حساب" SortExpression="شماره حساب">
            <EditItemTemplate>
                <asp:TextBox ID="TextBoxGridViewBankAccount" runat="server" Text='<%# Bind("TextBoxBankAccount") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="LabelGridViewBankAccount" runat="server" Text='<%# Bind("TextBoxBankAccount") %>'></asp:Label>
            </ItemTemplate>
            <HeaderStyle Font-Size="14px" />
            <ItemStyle Font-Size="12px" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="نام بانک" SortExpression="نام بانک">
            <EditItemTemplate>
                <asp:TextBox ID="TextBoxGridViewBankName" runat="server" Text='<%# Bind("BankName") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="LabelGridViewBankName" runat="server" Text='<%# Bind("BankName") %>'></asp:Label>
            </ItemTemplate>
            <HeaderStyle Font-Size="14px" />
            <ItemStyle Font-Size="12px" />
        </asp:TemplateField>
        <asp:CommandField ShowSelectButton="True" >
        <ItemStyle Font-Size="12px" />
        </asp:CommandField>
    </Columns>
    <FooterStyle BackColor="#CCCC99" />
    <PagerStyle ForeColor="Black" HorizontalAlign="Right" BackColor="#F7F7DE" />
    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="White" />
</asp:GridView>

I set the DataSource with the follwing code :

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        LabelTitr.Text = "Add Banks";
        LabelResult.Text = "";
        if (Session["Username"] != null)
        {
            string permission = "";
            bool login = PublicMethods.CheckUsernamePass(Session["Username"].ToString(), Session["Password"].ToString(), out permission);
            if (!login)
            {
                permission = "";
                Response.Redirect("../Default.aspx");
                Session["Username"] = Session["Password"] = null;
                return;
            }
        }
        else
        {
            Response.Redirect("../Default.aspx");
            Session["Username"] = Session["Password"] = null;
            return;
        }

        if (!IsPostBack)
            BindDataToGridView1();
    }
    catch (Exception ex)
    {
        LabelResult.Text = ex.Message;
    }
}

void BindDataToGridView1()
{
    try
    {
        DataSet1 dataSet = new DataSet1();
        DataClasses2DataContext dbc2 = new DataClasses2DataContext();
        var Definitions = dbc2.Definitions;
        if (Definitions.Count() <= 0) return;
        foreach (var Definition in Definitions)
        {
            string bankName = dbc2.Banks.Where(c => c.BankID == Definition.BankID).First().BankName;
            string CheckBox = "<input name=\"CheckBoxSubmitChanges\" type=\"checkbox\" value=" + Definition.DefinitionID + " />";
            dataSet.DataTableBanks.Rows.Add(bankName, Definition.BankAccount, Definition.MerchantID, Definition.TerminalID, Definition.TerminalID);
            GridView1.DataSource = dataSet.DataTableBanks;
        }
        GridView1.DataBind();
    }
    catch (Exception ex)
    {
        LabelResult.Text = ex.Message;
    }
}

and this is GridView1_SelectedIndexChanged method :

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    GridViewRow row = GridView1.SelectedRow;
    string temp = row.Cells[4].Text;
    LabelResult.Text = temp;
}

But always temp string is empty !!!
What’s wrong with it ?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T13:58:00+00:00Added an answer on May 16, 2026 at 1:58 pm

    If it’s a TemplateField, you have to use the FindControl(“control ID”) option, not the text fo the cell. I count cell 4 as being a templatefield…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a asp.net webpage with a GridView <asp:GridView ID=grid_view runat=server AllowPaging=True AutoGenerateColumns=False BackColor=White
I have a simple gridview <asp:GridView ID=GridView1 runat=server DataKeyNames=OriginatorID AutoGenerateColumns=False AllowPaging=True OnPageIndexChanging=GridView1_PageIndexChanging PageSize=5 OnPreRender=GridView1_PreRender>
I have a gridview like below: <asp:GridView DataKeyNames=TransactionID AllowSorting=True AllowPaging=TrueID=grvBrokerage runat=server AutoGenerateColumns=False CssClass=datatable Width=100%
I want to provide custom paging in grid view. <asp:GridView ID=gvFirst runat=server AutoGenerateColumns=false AllowPaging=true
I have a GridView control setup like this: <asp:GridView ID=UserList AllowPaging=True PageSize=20 runat=server> ...
I have an ImageButton in a GridView. <asp:GridView ID=ItemGridView runat=server DataKeyNames=Id OnRowDataBound=ItemGridView_RowDataBound AllowPaging=True AllowSorting=True
Hey so I have a gridview as follows <asp:GridView ID=productListTable runat=server DataSourceID=srcProductListPerCustomer AutoGenerateColumns=False AlternatingRowStyle-CssClass=tr_dark
I have a GridView that looks something like this: <asp:GridView ID=GridView1 AllowPaging=true OnRowCommand=RowCommand OnPageIndexChanging=gridView_PageIndexChanging
I have this code in my aspx page: <form id=form2 runat=server> <asp:ScriptManager ID=ItemsScriptManager runat=server
I have a GridView control on an ASP page, which I've bound to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.