Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 08, 2013 08:49 AM by yumil
Member
19 Points
40 Posts
Feb 08, 2013 07:14 AM|LINK
I would like to check the selected dropdownlist value in gridview while update row button in vb.
for ex. if dropdownlist value =1 then cancel update else update.
147 Points
256 Posts
Feb 08, 2013 07:21 AM|LINK
Hi,
You can use this in Loop for each row
Dim txtDescrip As DropDownList = DirectCast(dgv.Rows(RowIndex).Cells(CellIndex).FindControl("txtDescrip"), DropDownList)
While RowIndex is your iterate variable like i,j etc.
And CellIndex is your column Index. [Column Index starts from 0].
Regards,
Jagadeesh
Feb 08, 2013 08:06 AM|LINK
thanks for reply,
but I do not need loop because I use edit-update button on each row.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" style="position: relative; top: 5px; left: 2px; width: 769px;" EnableModelValidation="True"> <Columns> <asp:CommandField ButtonType="Button" CancelText="cancel" InsertText="" ShowEditButton="True" UpdateText="update" DeleteText="" NewText="" SelectText="" /> <asp:TemplateField HeaderText="opadsoyad" SortExpression="opadsoyad"> <EditItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="opadsoyad" DataValueField="operatorno" > </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("operatorno") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="makkod" HeaderText="m.kod" SortExpression="makkod" ReadOnly="True" /> <asp:BoundField DataField="arizayeri" HeaderText="arz.yeri" SortExpression="arizayeri" ReadOnly="True" /> <asp:BoundField DataField="bastarih" HeaderText="başlama" DataFormatString="{0:HH:mm}" SortExpression="bastarih" ReadOnly="True" /> <asp:BoundField DataField="ArzSüre" HeaderText="ArzSüre" SortExpression="ArzSüre" ReadOnly="True" /> <asp:BoundField DataField="nMakinaID" HeaderText="ID" SortExpression="nMakinaID" /> </Columns> </asp:GridView>
168 Points
41 Posts
Feb 08, 2013 08:24 AM|LINK
On gridview_updateEvent Dim ddl As DropDownList = DirectCast(gridview1.Rows(e.RowIndex).FindControl("txtDescrip"), DropDownList) if ddl.selectedValue=1 Then 'task else 'task End if
Feb 08, 2013 08:36 AM|LINK
thanks this is work. last question;
in below example how can I cancel update operation if ddl.SelectedValue = 0 ?
or do I have to use another gridview event ?
Protected Sub GridView1_RowUpdating..
Dim ddl As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("DropDownList1"), DropDownList)
If ddl.SelectedValue = 0 Then
Else
End If End Sub
Feb 08, 2013 08:45 AM|LINK
Hi Yumil,
You no need to do anything to cancel update if selected value is 0.
Just don't write code in like this,Instead of this try to use
If ddl.selectedValue isNot 0 then
//write your code for update
End if
it will not allow update if selectedValue is 0.
Please mark answer if you find helpful.
Feb 08, 2013 08:49 AM|LINK
thanks for all answers. I found the result. If dropdownlist selected value 0 then cancel the updating. as follows.
Protected Sub GridView1_RowUpdating
e.Cancel = True
End If
End Sub
yumil
Member
19 Points
40 Posts
Dropdownlist selected value control before update row in Gridview (Vs2008-vb)
Feb 08, 2013 07:14 AM|LINK
I would like to check the selected dropdownlist value in gridview while update row button in vb.
for ex. if dropdownlist value =1 then cancel update else update.
jagadeesh.bo...
Member
147 Points
256 Posts
Re: Dropdownlist selected value control before update row in Gridview (Vs2008-vb)
Feb 08, 2013 07:21 AM|LINK
Hi,
You can use this in Loop for each row
Dim txtDescrip As DropDownList = DirectCast(dgv.Rows(RowIndex).Cells(CellIndex).FindControl("txtDescrip"), DropDownList)yumil
Member
19 Points
40 Posts
Re: Dropdownlist selected value control before update row in Gridview (Vs2008-vb)
Feb 08, 2013 08:06 AM|LINK
thanks for reply,
but I do not need loop because I use edit-update button on each row.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
style="position: relative; top: 5px; left: 2px; width: 769px;"
EnableModelValidation="True">
<Columns>
<asp:CommandField ButtonType="Button" CancelText="cancel"
InsertText="" ShowEditButton="True" UpdateText="update" DeleteText=""
NewText="" SelectText="" />
<asp:TemplateField HeaderText="opadsoyad" SortExpression="opadsoyad">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
DataTextField="opadsoyad" DataValueField="operatorno"
>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("operatorno") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="makkod" HeaderText="m.kod"
SortExpression="makkod" ReadOnly="True" />
<asp:BoundField DataField="arizayeri" HeaderText="arz.yeri"
SortExpression="arizayeri" ReadOnly="True" />
<asp:BoundField DataField="bastarih" HeaderText="başlama" DataFormatString="{0:HH:mm}"
SortExpression="bastarih" ReadOnly="True" />
<asp:BoundField DataField="ArzSüre" HeaderText="ArzSüre"
SortExpression="ArzSüre" ReadOnly="True" />
<asp:BoundField DataField="nMakinaID" HeaderText="ID"
SortExpression="nMakinaID" />
</Columns>
</asp:GridView>
Harpreet09
Member
168 Points
41 Posts
Re: Dropdownlist selected value control before update row in Gridview (Vs2008-vb)
Feb 08, 2013 08:24 AM|LINK
On gridview_updateEvent Dim ddl As DropDownList = DirectCast(gridview1.Rows(e.RowIndex).FindControl("txtDescrip"), DropDownList) if ddl.selectedValue=1 Then 'task else 'task End ifRegards
Harpreet Singh
yumil
Member
19 Points
40 Posts
Re: Dropdownlist selected value control before update row in Gridview (Vs2008-vb)
Feb 08, 2013 08:36 AM|LINK
thanks this is work. last question;
in below example how can I cancel update operation if ddl.SelectedValue = 0 ?
or do I have to use another gridview event ?
Protected Sub GridView1_RowUpdating..
Dim ddl As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("DropDownList1"), DropDownList)
If ddl.SelectedValue = 0 Then
Else
End If
End Sub
Harpreet09
Member
168 Points
41 Posts
Re: Dropdownlist selected value control before update row in Gridview (Vs2008-vb)
Feb 08, 2013 08:45 AM|LINK
Hi Yumil,
You no need to do anything to cancel update if selected value is 0.
Just don't write code in like this,Instead of this try to use
If ddl.selectedValue isNot 0 then
//write your code for update
End if
it will not allow update if selectedValue is 0.
Please mark answer if you find helpful.
Regards
Harpreet Singh
yumil
Member
19 Points
40 Posts
Re: Dropdownlist selected value control before update row in Gridview (Vs2008-vb)
Feb 08, 2013 08:49 AM|LINK
thanks for all answers. I found the result. If dropdownlist selected value 0 then cancel the updating. as follows.
Protected Sub GridView1_RowUpdating
Dim ddl As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("DropDownList1"), DropDownList)
If ddl.SelectedValue = 0 Then
e.Cancel = True
End If
End Sub