Re: [2005] gridview problems
Can you be more specific about your problem? Is it erroring somewhere or just not working?
Re: [2005] gridview problems
thx for the reply.
i assume that u are asking my 2nd problem, yea.. it is not working. i don't get any error in that.
Re: [2005] gridview problems
For 2, you want to use the EditItemTemplate, but you've not given any more info aside from what you want. Show code.
Re: [2005] gridview problems
thx for the reply n here is my gridview code
HTML Code:
<asp:GridView ID="GridView1" HeaderStyle-CssClass=".viewgrid1_header" AutoGenerateEditButton="true" AutoGenerateSelectButton="true" AllowPaging="True" OnPageIndexChanging="changing" AutoGenerateColumns="False" runat="server" >
<HeaderStyle BackColor="#D9D9D9" CssClass="viewgrid1_header" HorizontalAlign="Center" Font-Bold="True" />
<RowStyle BackColor="#ECECEC" />
<AlternatingRowStyle BackColor="White"/>
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" InsertVisible="False" />
<asp:BoundField DataField="EMPLID" HeaderText="EMPLID" InsertVisible="False" ReadOnly="True" SortExpression="EMPLID" />
<asp:TemplateField HeaderText="List">
<ItemTemplate><asp:Label ID="lbl" runat="Server"></asp:Label></ItemTemplate>
<EditItemTemplate><asp:DropDownList ID="ddl" runat="server"></asp:DropDownList> </EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate><asp:Label ID="lbl1" runat="server"><%#Eval("Status")%></asp:Label></ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl1" runat="Server">
<asp:ListItem>tes</asp:ListItem>
<asp:ListItem>in progress</asp:ListItem>
<asp:ListItem>approved</asp:ListItem>
<asp:ListItem>rejected</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Leave_Type" HeaderText="Leave_Type" SortExpression="Leave_Type" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
<asp:BoundField DataField="Start_Date" HeaderText="Start_Date" SortExpression="Start_Date" />
<asp:BoundField DataField="End_Date" HeaderText="End_Date" SortExpression="End_Date" />
</Columns>
<PagerStyle HorizontalAlign="Right" BorderStyle="None" BorderColor="White" ForeColor="Orange"/>
<PagerSettings Mode="NumericFirstLast" FirstPageText="First" LastPageText="Last" Position="Top"/>
</asp:GridView>
and here is my code behind
Code:
Private Sub ConnectDB()
Dim con As SqlConnection
Dim com As SqlCommand
Dim adapter As New SqlDataAdapter
Dim dset As New Data.DataSet
Dim sql, table As String
sql = "select * from TrLeaveRequest"
table = "TrLeaveRequest"
con = New SqlConnection("server=(local);uid=work;pwd=123456;database=work")
con.Open()
com = New SqlCommand(sql, con)
adapter.SelectCommand = com
adapter.Fill(dset, Table)
GridView1.DataSource = dset
GridView1.DataBind()
con.Close()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ConnectDB()
End Sub
Protected Sub changing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
GridView1.PageIndex = e.NewPageIndex
ConnectDB()
End Sub
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
End Sub
Protected Sub GridView1_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles GridView1.SelectedIndexChanging
Dim index As Integer
index = e.NewSelectedIndex
TextBox1.Text = GridView1.Rows(index).Cells(1).Text
End Sub
so is there anything wrong with my code?
Re: [2005] gridview problems
So at first glance, this seems fine. You should be able to enter edit mode with those edit controls in place.
What then is the problem? Try to be more specific than "still it won't work".
Re: [2005] gridview problems
when i pressed the edit button it does nothing. the gridview don't change into editable control.
could there be any possibility that my vs2005 that is went wrong?
Re: [2005] gridview problems
The first question for you would be, did you set it up right? In order to verify that you have set it up right, compare what you did with this MSDN article...
http://msdn2.microsoft.com/en-us/library/ms972948.aspx
Re: [2005] gridview problems
from the link above, looks like i need an update command n update parameter, is that right?
coz both sqldatasource n objectdatasource has those command
Code:
<asp:SqlDataSource ID="productDataSource" Runat="server"
SelectCommand="SELECT [ProductName], [ProductID],
[UnitPrice], [UnitsInStock] FROM [Products]"
UpdateCommand="UPDATE [Products] SET [ProductName] =
@ProductName, [UnitPrice] = @UnitPrice, [UnitsInStock] =
@UnitsInStock WHERE [ProductID] = @original_ProductID"
ConnectionString="<%$ ConnectionStrings:NWConnectionString %>">
<UpdateParameters>
<asp:Parameter Type="String"
Name="ProductName"></asp:Parameter>
<asp:Parameter Type="Decimal"
Name="UnitPrice"></asp:Parameter>
<asp:Parameter Type="Int16"
Name="UnitsInStock"></asp:Parameter>
<asp:Parameter Type="Int32" Name="ProductID"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
Code:
<asp:ObjectDataSource ID="productDataSource"
Runat="server" TypeName="ProductDAL"
SelectMethod="GetProducts" EnablePaging="True"
SelectCountMethod="TotalNumberOfProducts"
UpdateMethod="UpdateProduct">
<UpdateParameters>
<asp:Parameter Type="Int32" Name="ProductID"></asp:Parameter>
<asp:Parameter Type="String"
Name="productName"></asp:Parameter>
<asp:Parameter Type="Decimal"
Name="unitPrice"></asp:Parameter>
<asp:Parameter Type="Int32"
Name="unitsInStock"></asp:Parameter>
</UpdateParameters>
</asp:ObjectDataSource>
Re: [2005] gridview problems
for the 1st problem instead of using gridview, i use repeater.
i don't find any clue about how to do that using gridview :(