Gridview template field datasource

ryeguy

New Member
I've placed a gridview on my asp.net page, and am using a sql call to obtain the datasource. In the sql call, it brings the data for all the fields(name, address, phone, type)On the gridview, there are 2 fields (phone, type) that need to be template fields rather than bound field, during edit, and textboxes or labels (whichever) in the Item template. When I run the code, the datagrid completes and fills in - minus the information for the phone or type fields (template fields).How do I databind the fields so the information will show up properly.I've included my code.Any help would be greatly appreciated. Thanks in advance!GRIDVIEW:\[code\] <asp:GridView ID="gvMTM" runat="server" AllowPaging="True" DataKeyNames="MTMID" AutoGenerateColumns="False" AutoGenerateEditButton="True" OnRowEditing="gvMTM_RowEditing" OnRowUpdating="gvMTM_UpdateRowEditing" OnRowCancelingEdit="gvMTM_CancelRowEditing" > <Columns> <asp:BoundField DataField="MTMID" HeaderText="ID" /> <asp:BoundField DataField="MTMName" HeaderText="Name" /> <asp:BoundField DataField="Add1" HeaderText="Add1" /> <asp:BoundField DataField="Add2" HeaderText="Add2" /> <asp:BoundField DataField="City" HeaderText="City" /> <asp:BoundField DataField="ST" HeaderText="ST" /> <asp:BoundField DataField="Zip" HeaderText="Zip" /> <asp:BoundField DataField="Email" HeaderText="Email" /> <asp:TemplateField HeaderText="Phone#"> <EditItemTemplate> <asp:TextBox ID="txtPhoneEdit" runat="server"></asp:TextBox> <asp:MaskedEditExtender ID="TemptxtPhone_MaskedEditExtender" runat="server" CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder="" CultureDateFormat="" CultureDatePlaceholder="" CultureDecimalPlaceholder="" CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True" TargetControlID="TemptxtPhone"> </asp:MaskedEditExtender> </EditItemTemplate> <ItemTemplate> <asp:TextBox ID="txtPhoneRead" runat="server" BorderStyle="None"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="RR"> <EditItemTemplate> <asp:DropDownList ID="ddRREdit" runat="server" Height="16px" Width="100px" DataTextField="Railroad" DataValueField="RRID"> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:TextBox ID="txtRRRead" runat="server" BorderStyle="None"></asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns></asp:GridView>\[/code\]on .CS page:\[code\] gvMTM.DataSource = code.GetMTMList(); gvMTM.DataBind();\[/code\]SQL call\[code\] public DataTable GetMTMList() { try { SQLCON = new SqlConnection(connectionString); SQLCON.Open(); SQLCmd = new SqlCommand("spGetMTMList", SQLCON); SQLCmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter adapter = new SqlDataAdapter(SQLCmd); DataTable Detailtable = new DataTable(); adapter.Fill(Detailtable); return Detailtable; } catch (Exception ex) { HttpContext.Current.Response.Redirect("~/ErrorRedirect.aspx?" + ex.Message, false); return null; } finally { SQLCON.Close(); } }\[/code\]
 
Back
Top