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 6062815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:05:41+00:00 2026-05-23T09:05:41+00:00

How do I get the DataGrid row data while selecting a DataGrid. For example,

  • 0

How do I get the DataGrid row data while selecting a DataGrid. For example, while selecting a row in a DataGrid , I want to show that field data in concern TextBoxes. Please see the code snippet below

    <asp:TextBox ID="tbCode" runat="server" TabIndex="0"                        
                    style="width: 82px; position: absolute; top: 16px; left: 63px; width: 88px; height: 24px;" 
                    MaxLength="5"></asp:TextBox>
                <asp:Label ID="lblCode" runat="server" Text="Code"                          
                    style="width: 45px; position: absolute; top: 18px; left: 18px; height: 22px;">
 </asp:Label>
            <asp:TextBox ID="tbCode" runat="server" TabIndex="0"                        
                    style="width: 82px; position: absolute; top: 16px; left: 63px; width: 88px; height: 24px;" 
                    MaxLength="5"></asp:TextBox>
                <asp:Label ID="lblCode" runat="server" Text="Code"                          
                    style="width: 45px; position: absolute; top: 18px; left: 18px; height: 22px;">
</asp:Label>

   <asp:DataGrid ID="Grid" runat="server" AllowPaging="True" DataKeyField="Team_Id"
        AutoGenerateColumns="False" CellPadding="2" ForeColor="#333333" GridLines="None" 
        OnPageIndexChanged="Grid_PageIndexChanged" OnCancelCommand="Grid_CancelCommand"
        style="position:absolute; top: 122px; left: 13px; width: 545px; bottom: 238px;"
        OnDeleteCommand="Grid_DeleteCommand" OnEditCommand="Grid_EditCommand"             

        OnUpdateCommand="Grid_UpdateCommand" TabIndex="3" BorderStyle="Solid" 
        BorderWidth="1">

    <Columns>
        <asp:BoundColumn HeaderText="Code" DataField="Team_Code" ReadOnly="true"> </asp:BoundColumn>
        <asp:BoundColumn HeaderText="Team Name" DataField="Team_Name"> </asp:BoundColumn>
        <asp:EditCommandColumn  EditText="Edit" CancelText="Cancel" UpdateText="Update" HeaderText="Edit"> </asp:EditCommandColumn>
        <asp:ButtonColumn CommandName="Delete" HeaderText="Delete" Text="Delete"> </asp:ButtonColumn>            
    </Columns>          
    </asp:DataGrid>

updated code

    protected void GetSelectedData(Object src, EventArgs e)
{
    String TeamId = Grid.DataKeys[Grid.SelectedIndex].ToString();
    using (OdbcConnection DbConnection = new OdbcConnection(ConfigurationManager.AppSettings["ConnectionStr"]))
    {
        DbConnection.Close();
        string cmdText = "SELECT Team_Code,Team_Name FROM team_details WHERE Team_Id=?";
        OdbcCommand cmd = new OdbcCommand(cmdText, DbConnection);
        cmd.Parameters.Add("?Id", OdbcType.Int).Value = Convert.ToInt32(TeamId);
        DbConnection.Open();
        OdbcDataReader DR = cmd.ExecuteReader();
        while (DR.Read())
        {
            tbCode.Text = DR.GetValue(0).ToString();
            tbName.Text = DR.GetValue(1).ToString();
        }

    }
}

  <asp:DataGrid ID="Grid" runat="server" AllowPaging="True" DataKeyField="Team_Id"
        AutoGenerateColumns="False" CellPadding="2" ForeColor="#333333" GridLines="None" 
        OnSelectedChanged="GetSelectedData" OnCancelCommand="Grid_CancelCommand"
        style="position:absolute; top: 122px; left: 13px; width: 545px; bottom: 238px;"
        OnDeleteCommand="Grid_DeleteCommand" OnEditCommand="Grid_EditCommand"               
        OnUpdateCommand="Grid_UpdateCommand" TabIndex="3" BorderStyle="Solid" 
        BorderWidth="1">
    <Columns>
        <asp:BoundColumn HeaderText="Code" DataField="Team_Code" ReadOnly="true"> </asp:BoundColumn>
        <asp:BoundColumn HeaderText="Team Name" DataField="Team_Name"> </asp:BoundColumn>
        <asp:EditCommandColumn  EditText="Edit" CancelText="Cancel" UpdateText="Update" HeaderText="Edit"> </asp:EditCommandColumn>
        <asp:ButtonColumn CommandName="Delete" HeaderText="Delete" Text="Delete"> </asp:ButtonColumn>            
        <asp:TemplateColumn>
            <ItemTemplate>
                <asp:LinkButton runat="server" CommandName="select" text="select team" />                    
            </ItemTemplate>
        </asp:TemplateColumn> 
    </Columns>
  </asp:DataGrid>
  • 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-23T09:05:41+00:00Added an answer on May 23, 2026 at 9:05 am

    Use GridViewSelection Event for that

        OnSelectedIndexChanged="Grid_SelectedIndexChanged"
    
    
       void Grid_SelectedIndexChanged(Object sender, EventArgs e)
       {
    
         // Get the currently selected row using the SelectedRow property.
          GridViewRow row = Grid.SelectedRow;
    
         //Fill textboxes here
         Code.Text =  row.Cells[0].Text;
    
        }
    

    Oh yeah this code is for grid.So if you are using datagrid You need to Set the Select CommandField in the Grid so that the SelectedIdexChanged event will fire up

    Here is code sample that will definitely help you

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

Sidebar

Related Questions

While working with an excel file (.xlsx), the data I get from it is
I am trying to get a DataGrid under CE 5.0 / .NET CF 2.0
We get a large amount of data from our clients in pdf files in
I get an XML file From a web service. Now I want to get
I have a data set whose elements are displayed as rows in a DataGrid.
I have an 'ObservableCollection' that stores formatted ColumnLabels that need pasting into DataGrid. The
I am having problem loading data into Nested datagrid. When the user clicks on
i have a datagrid and every row has a checkbox on it. also every
We get the following error; The request was aborted: Could not create SSL/TLS secure
I get an Access is Denied error message when I use the strong name

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.