Datagrid questions

L

lloyd

i got couple of dotNet questions pertaining to dataGrid, if you could
help me out.

1) how do i store more than one key value in the DATAKEY element. So
far from what i have seen it doesnot seem possible, this is to store
composite primary keys? i have found out that i need to join the
composite values with a delimiter in the sql statement and then bind
it. is it not possible to do it in any other way ??

2) i need to access lets say the contents of the 4 row 5th column of a
datagrid and this is to be accessed on a button click, not on any of
the datagrid events. How do i do this ??

3) if i needed to access the contents of the 4th row 5th column in the
dataGRid event. How do i do this??

Please help me out, i am kinda stuck
 
K

Ken Cox [Microsoft MVP]

Hi Lloyd,

Here's some code that might get you going with items 2 and 3 on your list.
You just need to count the rows and columns (starting at 0) and insert the
values. Then you can read and write to that cell. Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]


Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Label1.Text = _
DataGrid1.Items(5).Cells(3).Text

End Sub

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource

Private Sub Button2_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button2.Click
DataGrid1.Items(5).Cells(3).Text = "Custom Text"
End Sub

<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
<P>
<asp:Label id="Label1" runat="server">Label</asp:Label></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
<P>
<asp:Button id="Button2" runat="server" Text="Custom
Text"></asp:Button></P>
</form>

Ken
 
E

Evert Wiesenekker

i got couple of dotNet questions pertaining to dataGrid, if you could
help me out.

1) how do i store more than one key value in the DATAKEY element. So
far from what i have seen it doesnot seem possible, this is to store
composite primary keys? i have found out that i need to join the
composite values with a delimiter in the sql statement and then bind
it. is it not possible to do it in any other way ??

2) i need to access lets say the contents of the 4 row 5th column of a
datagrid and this is to be accessed on a button click, not on any of
the datagrid events. How do i do this ??

3) if i needed to access the contents of the 4th row 5th column in the
dataGRid event. How do i do this??

Please help me out, i am kinda stuck

Here is another person who would like to know how to store more than
one key value, because I am grdding a table in which the Primary Key
contains two columns.

My temporary solution is at the moment to hide the two columns...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top