Click here to Skip to main content
15,845,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i bind the data from datasource to datagridview textbox column ??
Posted

U can bind textbox such as this..

XML
<asp:GridView ID="GridView" runat="server" AllowPaging="True" PageSize="10"
                    AllowSorting="True" AutoGenerateColumns="False"  DataSourceID="SqlDataSource1" >
                    <Columns>
                       <asp:TemplateField HeaderText="columnname">
                        <ItemTemplate>
                        <asp:TextBox ID="txtId" ReadOnly="true"  Text='<%#Eval("columnname ") %>'   runat="server" ></asp:TextBox>
                        </ItemTemplate>
                        </asp:TemplateField>
  </Columns>
                </asp:GridView>

                <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                    ConnectionString="<%$ connectionstring name %>"
                    SelectCommand="SELECT * FROM [tablename]"></asp:SqlDataSource>
 
Share this answer
 
see below example,
suppose in YourDataTable columns are like below,
LedgerID, LedgerName, LedgerPhNo


so, write code like this
VB
DataGridView1.DataSource = YourDataTable
DataGridView1.AutoGenerateColumns = False
DataGridView1.Columns(0).DataPropertyName = "LedgerID" 
DataGridView1.Columns(1).DataPropertyName = "LedgerName"
DataGridView1.Columns(2).DataPropertyName = "LedgerPhNo"

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900