Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
how can i bind the data from datasource to datagridview textbox column ??
Posted 14-Nov-12 19:46pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

U can bind textbox such as this..
 
<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>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

see below example,
suppose in YourDataTable columns are like below,
LedgerID, LedgerName, LedgerPhNo

 
so, write code like this
DataGridView1.DataSource = YourDataTable
DataGridView1.AutoGenerateColumns = False
DataGridView1.Columns(0).DataPropertyName = "LedgerID" 
DataGridView1.Columns(1).DataPropertyName = "LedgerName"
DataGridView1.Columns(2).DataPropertyName = "LedgerPhNo"
Happy Coding!
Smile | :)
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 503
1 George Jonsson 311
2 CPallini 290
3 OriginalGriff 139
4 Prasad Khandekar 135
0 OriginalGriff 4,623
1 CPallini 3,410
2 Sergey Alexandrovich Kryukov 2,929
3 George Jonsson 2,319
4 Gihan Liyanage 2,077


Advertise | Privacy | Mobile
Web03 | 2.8.140905.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100