Advertisement
Advertisement
| 02.11.2008 at 12:10PM PST, ID: 23154190 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
|
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: |
Here's the sub that builds a blank gridview with one row:
Private Sub BuildUploadTable()
Dim dt As New DataTable
Dim dc As New DataColumn("description")
dtFiles.Columns.Add(dc)
Dim dr As DataRow = dtFiles.NewRow
dr("description") = "None"
dtFiles.Rows.Add(dr)
dsFiles.Tables.Add(dtFiles)
'gFiles.DataSource = dsFiles
gvFiles.DataSource = dtFiles
gvFiles.DataBind()
gvFiles.Visible = True
End Sub
Here's the part that's problematic:
Protected Sub gvFiles_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvFiles.RowCommand
If dtFiles.Rows.Count = 0 Then
dtFiles.Columns.Add("tbDesc", GetType(TextBox))
dtFiles.Columns.Add("Add", GetType(ButtonColumn))
dtFiles.Columns.Add("Remove", GetType(ButtonColumn))
End If
'Convert datagrid to dt
Dim gr As GridViewRow
Dim nr As DataRow
For Each gr In gvFiles.Rows
nr = dtFiles.NewRow
'BEGIN PROBLEM
nr(0) = CType(gr.FindControl("tbDesc"), TextBox).Text
nr(1) = "Add"
nr(2) = "Remove"
'END PROBLEM
dtFiles.Rows.Add(nr)
Next
If e.CommandName = "Add" Then
'Add new row to dt
nr = dtFiles.NewRow
dtFiles.Rows.Add(nr)
dsFiles.Tables.Add(dtFiles)
gvFiles.DataSource = dtFiles
gvFiles.DataBind()
gvFiles.Visible = True
ElseIf e.CommandName = "Remove" Then
dtFiles.Rows.RemoveAt(gvFiles.Rows(e.CommandArgument).RowIndex)
dsFiles.Tables.Add(dtFiles)
gvFiles.DataSource = dtFiles
gvFiles.DataBind()
gvFiles.Visible = True
End If
End Sub
|
| Microsoft |
| Apple |
| Internet |
| Gamers |
| Digital Living |
| Virus & Spyware |
| Hardware |
| Software |
| ITPro |
| Developer |
| Storage |
| OS |
| Database |
| Security |
| Programming |
| Web Development |
| Networking |
| Other |
| Community Support |
| 02.11.2008 at 02:22PM PST, ID: 20870912 |
| 02.15.2008 at 02:37PM PST, ID: 20906671 |
| 02.15.2008 at 02:41PM PST, ID: 20906699 |
| 02.19.2008 at 06:46AM PST, ID: 20928728 |
| 02.19.2008 at 06:52AM PST, ID: 20928830 |
| 02.19.2008 at 10:29AM PST, ID: 20931099 |
| 02.20.2008 at 07:18AM PST, ID: 20938554 |
| 02.20.2008 at 08:32AM PST, ID: 20939348 |
| 02.20.2008 at 08:39AM PST, ID: 20939439 |
| 02.20.2008 at 09:03AM PST, ID: 20939711 |
| 02.20.2008 at 09:10AM PST, ID: 20939788 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: |
For Each gr In gFiles.Rows
nr = dtFiles.NewRow
fileU = CType(gr.FindControl("FileToUpload"), FileUpload)
tb = CType(gr.FindControl("tbDesc"), TextBox)
bAdd = CType(gr.FindControl("btnAdd"), LinkButton)
nr(0) = fileU
nr(1) = tb
nr(2) = bAdd
dtFiles.Rows.Add(nr)
Next
gFiles.DataSource = dtFiles
gFiles.DataBind()
|
| 02.20.2008 at 09:24AM PST, ID: 20939904 |
| 02.20.2008 at 09:27AM PST, ID: 20939929 |
| 02.20.2008 at 09:50AM PST, ID: 20940113 |
| 02.20.2008 at 10:26AM PST, ID: 20940441 |
| 02.20.2008 at 10:35AM PST, ID: 20940489 |
| 02.20.2008 at 10:35AM PST, ID: 20940492 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: |
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="DynamicUploader.aspx.vb"
Inherits="DynamicUploader" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<style type="text/css">
body { font-family: Tahoma; font-size: 10pt; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" Height="50%" Width="100%" AutoGenerateColumns="False"
Font-Names="Tahoma" Font-Size="10pt" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Upload">
<ItemTemplate>
<asp:FileUpload ID="FileUpload" runat="server" Font-Names="Tahoma" Font-Size="10pt"
Width="100%" />
<asp:TextBox ID="FileName" runat="server" Width="100%" Visible="false" Text='<%# Eval("FileName") %>'></asp:TextBox>
</ItemTemplate>
<HeaderStyle Width="30%" />
</asp:TemplateField>
<asp:BoundField DataField="Description" HeaderText="Description">
<HeaderStyle Width="40%" />
</asp:BoundField>
<asp:ButtonField CommandName="Add" Text="Add">
<HeaderStyle Width="5%" />
</asp:ButtonField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
|
| 02.20.2008 at 10:35AM PST, ID: 20940494 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: |
Imports System
Imports System.Data
Partial Public Class DynamicUploader
Inherits System.Web.UI.Page
Private _UploadData As DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Page.IsPostBack Then
Me.CreateUploadTable()
Else
_UploadData = DirectCast(Session("UploadData"), DataTable)
End If
Me.GridView1.DataSource = _UploadData
Me.GridView1.DataBind()
End Sub
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "Add" Then
Me.SaveUploadedFileNames()
Dim dr As DataRow = _UploadData.NewRow()
_UploadData.Rows.Add(dr)
Session("UploadData") = _UploadData
Me.GridView1.DataSource = _UploadData
Me.GridView1.DataBind()
End If
End Sub
Private Sub CreateUploadTable()
_UploadData = New DataTable("Upload")
_UploadData.Columns.Add("FileName")
_UploadData.Columns.Add("Description")
Dim dr As DataRow = _UploadData.NewRow()
_UploadData.Rows.Add(dr)
Session("UploadData") = _UploadData
End Sub
Private Sub SaveUploadedFileNames()
For i As Integer = 0 To Me.GridView1.Rows.Count - 1
Dim row As GridViewRow = Me.GridView1.Rows(i)
Dim upload As FileUpload = TryCast(row.FindControl("FileUpload"), FileUpload)
Dim textBox As TextBox = TryCast(row.FindControl("FileName"), TextBox)
If upload IsNot Nothing AndAlso textBox IsNot Nothing AndAlso textBox.Text.Length = 0 Then
Dim dr As DataRow = _UploadData.Rows(i)
dr("FileName") = upload.FileName
End If
Next
Session("UploadData") = _UploadData
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
Dim upload As FileUpload = TryCast(e.Row.FindControl("FileUpload"), FileUpload)
Dim textBox As TextBox = TryCast(e.Row.FindControl("FileName"), TextBox)
If upload IsNot Nothing AndAlso textBox IsNot Nothing Then
textBox.Visible = (textBox.Text.Length > 0)
upload.Visible = Not textBox.Visible
End If
End Sub
End Class
|
| 02.20.2008 at 01:00PM PST, ID: 20941906 |