使用动态gridview控件。 [英] Using dynamic gridview control .

查看:71
本文介绍了使用动态gridview控件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加girdview控制一个特定列并想要检查总数是否超过1总数超过1然后用户不应该被允许添加另一行到gridview否则如果总数不超过1然后用户允许动态添加新行。

这是代码

如果ViewState(CurrentTable)IsNot Nothing那么
Dim dtCurrentTable As DataTable = DirectCast(ViewState(CurrentTable),DataTable)
Dim drCurrentRow As DataRow = Nothing
如果dtCurrentTable.Rows.Count> 0然后
For i As Integer = 1 to dtCurrentTable.Rows.Count
Dim txtfunob As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex).Cells(1).FindControl(txtfuncobj),TextBox)
Dim txtmeasur As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex).Cells(2).FindControl(txtmeasuredvar),TextBox)
Dim txtd_line As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex)。 Cells(3).FindControl(txtdeadline),TextBox)
Dim txtwtfact As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex).Cells(4).FindControl(txtweight_fact),TextBox)
Dim temp As String = txtwtfact.Text.ToString
tot = tot + Convert.ToDouble(temp)
'count = count + 1
'MsgBox(count)
MsgBox(tot )
如果tot = 1.0F则
lbltot.Visible = True
lbltot.Text =你的加权因子变成一个..
结束如果
如果tot> 1.0F然后
lbltot.Visible = True
lbltot.Text =你的加权系数超过1 ..
否则
lbltot.Visible = False
结束如果

drCurrentRow = dtCurrentTable.NewRow()
drCurrentRow(RowNumber)= i + 1

dtCurrentTable.Rows(i - 1)(Col1)= txtfunob.Text
dtCurrentTable.Rows(i - 1)(Col2)= txtmeasur.Text
dtCurrentTable.Rows(i-1)(Col3)= txtd_line.Text
dtCurrentTable .Rows(i - 1)(Col4)= txtwtfact.Text

rowIndex + = 1
下一个
dtCurrentTable.Rows.Add(drCurrentRow)
ViewState (CurrentTable)= dtCurrentTable

grv_set_func_obj.DataSource = dtCurrentTable
grv_set_func_obj.DataBind()

Dim txtfnobj As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex).Cells(1).FindControl(txtfuncobj),TextBox)
txtfnobj.Focus()

结束如果

解决方案

可能你正在寻找这个....



gridview-add-new-row

动态添加和删除行

I want to add the girdview controls one perticular column and want to check wheather the total exceeds 1 or not if total exceeds 1 then user should not be allowed to add another row to gridview else if total does not exceeds 1 then user allowed to add new row dynamically.
Here is the code

If ViewState("CurrentTable") IsNot Nothing Then
           Dim dtCurrentTable As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)
           Dim drCurrentRow As DataRow = Nothing
           If dtCurrentTable.Rows.Count > 0 Then
               For i As Integer = 1 To dtCurrentTable.Rows.Count
                   Dim txtfunob As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex).Cells(1).FindControl("txtfuncobj"), TextBox)
                   Dim txtmeasur As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex).Cells(2).FindControl("txtmeasuredvar"), TextBox)
                   Dim txtd_line As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex).Cells(3).FindControl("txtdeadline"), TextBox)
                   Dim txtwtfact As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex).Cells(4).FindControl("txtweight_fact"), TextBox)
                   Dim temp As String = txtwtfact.Text.ToString
                   tot = tot + Convert.ToDouble(temp)
                   'count = count + 1
                   'MsgBox(count)
                   MsgBox(tot)
                   If tot = 1.0F Then
                       lbltot.Visible = True
                       lbltot.Text = " Your weighting factor becomes one.."
                   End If
                   If tot > 1.0F Then
                       lbltot.Visible = True
                       lbltot.Text = " Your weighting factor exceeds one.."
                   Else
                       lbltot.Visible = False
                   End If

                   drCurrentRow = dtCurrentTable.NewRow()
                   drCurrentRow("RowNumber") = i + 1

                   dtCurrentTable.Rows(i - 1)("Col1") = txtfunob.Text
                   dtCurrentTable.Rows(i - 1)("Col2") = txtmeasur.Text
                   dtCurrentTable.Rows(i - 1)("Col3") = txtd_line.Text
                   dtCurrentTable.Rows(i - 1)("Col4") = txtwtfact.Text

                   rowIndex += 1
               Next
               dtCurrentTable.Rows.Add(drCurrentRow)
               ViewState("CurrentTable") = dtCurrentTable

               grv_set_func_obj.DataSource = dtCurrentTable
               grv_set_func_obj.DataBind()

               Dim txtfnobj As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex).Cells(1).FindControl("txtfuncobj"), TextBox)
               txtfnobj.Focus()

           End If

解决方案

May be you r looking for this....

gridview-add-new-row
Dynamically-adding-and-deleting-rows


这篇关于使用动态gridview控件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆